Andrew, try this :
function GiveAnswer( id:Number ):Void { trace( "answer id: " + id ); } for( var aNum = 1 ; aNum <= 5 ; aNum++ ) { var answerButton = questionInterface["button_"+aNum]; answerButton.id = aNum; answerButton.onRelease = function(){ GiveAnswer(this.id); } } i hope it helps MauricioMassaia On 3/14/07, Nimrod Huberman <[EMAIL PROTECTED]> wrote:
You can set pointer to the question class in the button, and use it later in function . Use this code in the your question class: answerButton.handleBy = this; answerButton.onRelease = function() { handleBy.GiveAnswer(aNum);} -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andrew Sinning Sent: Monday, March 12, 2007 8: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! _______________________________________________ Flashcoders@chattyfig.figleaf.com 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 _______________________________________________ Flashcoders@chattyfig.figleaf.com 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
_______________________________________________ Flashcoders@chattyfig.figleaf.com 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