Copy link to clipboard
Copied
Hello,
I need to have several buttons that do the same behavior.
For brevity, I do not want to attribute to them each time a different instance name.
Is there a way to perform many buttons the same function (eg trace ("foo");?
And:
1) without converting all the buttons in a single symbol, this is because I often need to give different positions on the Stage;
2) without to write a different script for each button?
Thank you.
John.
Copy link to clipboard
Copied
if you want to control each individually (eg, change their positions relative to each other), the easiest way is to assign different instance names for each.
they could all be children of the same parent movieclip and you could encode one handler for the parent so you don't have to encode more than one handler.
Copy link to clipboard
Copied
You would want to use a for loop for your need and dynamically reference each button instance. In the below example, create 4 buttons on your stage at the root level and give them instance names of "btn1", "btn2", "btn3" & "btn4". Then insert the following on the root timeline.
stop();
for (var i:Number = 1; i <= 4; i++){
_root["btn"+i].onRollOver = function(){
trace("foo"+this._name);
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now