Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Several buttons that do the same behavior

Contributor ,
Jul 30, 2013 Jul 30, 2013

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.

TOPICS
ActionScript
572
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2013 Jul 30, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 20, 2013 Aug 20, 2013
LATEST

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);

                    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines