Hi,
Iam having 3 buttons in stage and three corresponding movieclips. When I clicked on one button, it should play its corresponding movieclip from the second frame. (Same case for the rest of the buttons)
Here the action for the three buttons are almost same, only the movieclip differs. In AS2, I can optimize the script for the above activity as below
for (var i = 1; i<=3; i++) {
_root["btn_"+i].onRelease = function() {
myname = this._name.split("_")[1];
_root["MC_"+myname].gotoAndPlay(2);
};
}
In AS3, I can able to write the equivalent script as below,
btn_1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
btn_2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
btn_3.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
var nam = event.target.name;
var mcaction = nam.split("_")[1];
this["mc_" + mcaction].gotoAndPlay(2);
}
My Question is ===>
is there any way to add the Event listeners for all the 3 buttons using "for loop" instead of initializing it for each buttons seperately ?
[Imagine if we have more than 10 buttons and it will be very boring to add the listener for each button in a seperate line ].
Thanks in Advance for your responses