all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

Dynamic Event Handler Functions



Dynamic Event Handler Functions Doc Gonzo
2/2/2006 11:33:03 PM
flash actionscript: Hi, I was trying to create some event handlers for butons in an efficient way,
in a small amount of code. I came up with this, thinking it wouldn't work, but
it does!.....but with a bug that I don't understand. look at it below.

now, this code creates event handlers for each button, however, all of the
buttons do the same thing. They all change the alpha of the LAST button in the
button list to 0...instead of changing their own alpha to 0.

any ideas?



function activateButtons():Void {
var buttonList:Array =
["button01","button02","button03","button04","button05"]
for(i= 0; i < buttonList.length; i++) {
tempName = buttonList[i]
tempObject = eval("menuShell." + tempName);
tempObject.onPress = function():Void {
tempObject._alpha = 0;
}
}
}
Re: Dynamic Event Handler Functions Doc Gonzo
2/3/2006 1:09:55 AM
I should say, I do know how to achieve what I'm trying to do in a much easier
fashion: using a class that I had already established anyway. However, I would
still like to know why this code doesn't work. thanks.
AddThis Social Bookmark Button