2 Replies Latest reply on Aug 20, 2013 7:00 AM by tx51chevy

    Several buttons that do the same behavior

    Jhon Carlo Level 1



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


      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.


        • 1. Re: Several buttons that do the same behavior
          kglad Adobe Community Professional & MVP

          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.

          1 person found this helpful
          • 2. Re: Several buttons that do the same behavior

            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.



            for (var i:Number = 1; i <= 4; i++){

                      _root["btn"+i].onRollOver = function(){