use  Delegate.create in your class so it has proper scope - the
onRelease anonymous function won't work because it loses scope when
defined within the class.

If you need to pass a param, do something like this in your class:

private function defineActions()
{
   var myDelegate:Object = myButton.onRelease = Delegate.create(this,
doSomething)
   myDelegate.answer = "Tomatoes"
}

private function doSomething()
{
  trace(arguments.caller.answer)
}

Jason Merrill
Bank of America  
Global Technology & Operations
Learning & Leadership Development 
eTools & Multimedia Team


 

>>-----Original Message-----
>>From: [EMAIL PROTECTED] 
>>[mailto:[EMAIL PROTECTED] On Behalf 
>>Of Andrew Sinning
>>Sent: Monday, March 12, 2007 2:14 PM
>>To: Flash Coders
>>Subject: [Flashcoders] correct way to set onRease of an 
>>arbitrary button
>>
>>(Putting aside whether or not this is best practice design, 
>>as I'm just trying to get my head around this.)
>>
>>I've put three buttons in _root.questionInterface called 
>>button_1, button_2, etc.  Elsewhere I have defined a class 
>>Question.  When an instance of Question is displayed, it 
>>needs to modify the onRelease of the three buttons so that 
>>the Question gets notified when each button gets released.
>>
>>Within the "Display" method of the Question, I want to do 
>>something like
>>
>>for (var aNum=1; aNum<=5; aNum++) {
>>
>>    var answerButton = _root.questionInterface["button_"+aNum];
>>    // pseudo code:
>>    make the onRelease of answerButton make a call to the function
>>AnswerSelected(aNum) inside of this
>>    //
>>
>>    // I have tried the following, but it's not right
>>    answerButton.onRelease = function() { this.GiveAnswer(aNum);};
>>
>>    
>>}
>>
>>
>>Any help greatly appreciated.  Thanks!
>>
>>
>>_______________________________________________
>>[email protected]
>>To change your subscription options or search the archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training 
>>http://www.figleaf.com http://training.figleaf.com
>>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to