I'm feeling like an idiot here. Please help me.
I'm building a group of buttons (array or not, doesn't matter to me,) and I need a way for each button to report its own index. I've done this before with movie clip objects, by simply adding an id property to the movie clip. I set the index when I created the movie clip, and then I could retrieve it from the button's release event. However, the same technique does not seem to work with buttons. When I add a custom property to the button object, it's reported as undefined.
Here's my latest attempt (I've abandoned arrays for the virtual array form at this point)
HTML Code:
//code in frame
init();
function init(){
//set up buttons
//set up sounds
//Button.prototype.index = 0;
theSound = new Sound();
for (i = 0; i <= 5; i++){
btnName = "btn_" + i;
btnDepth = 100 + i;
_root.attachMovie("Button", btnName, btnDepth);
theButton = eval(btnName);
theButton.label = btnName;
theButton._x = 50
theButton._y = i * 30;
theButton.id = i;
theButton.soundName = "audio/ - Track0" + i + ".mp3";
theButton.onRelease = function(){
trace(_this.id);
trace(_this.soundName);
//theSound.loadSound(soundName, true);
//theSound.start();
} // end button release
} // end for loop
} // end init
Both soundName and id are reported as undefined from within the event handler. Similar code works flawlessly with movie clips.
Please make me feel like an idiot! Tell me I'm missing something simple.
I suspect the button object simply doesn't allow these basic properties.
I think I can handle actionscript 2.0, but I don't really want to go there for this project.
Thanks in advance!
-Andy