2 Replies Latest reply on Jun 11, 2014 7:15 AM by Jnberg

    When I click on a object, I want an other object to return to its original position


      I have six objects (alla are symbols) lined up to the right of my stage. If i click on one object, the object animates from right to the center of the stage.

      Lets say I want to click on one of the remaining objects so it also animates to the center, but at the same time have the previous clicked object return to its original position. For example: I click on Object1 and it animates to the center. I click on Object4 and it animates to center, but also returns Object1. How do I do that? I'm a beginner to javascript, so I have no clue how to write the code for this action.

        • 1. Re: When I click on a object, I want an other object to return to its original position
          todd_rohrer Level 1

          I am very much not an expert, but browsing these forums and trying to figure out the answers helps me to learn. So here's what I came up with, and hopefully an expert can answer more fully.


          You can trigger an action on a symbol to "playReverse()".  This will start an animation from the last frame and play it back to the first frame.  In order to target a symbol, use the following commands:


          sym - basically says "start with the symbol I have selected".

          getSymbol("symbolName") - locates a symbol by the instance name

          $("elementName") - locates a DOM (document object model) element by the instance name (i.e. an object that is not a symbol).


          So, if both of your elements are on the stage, you can target one by adding this to object1 as a click action:



          This code will play the reverse animation when object 1 is clicked, but it won't distinguish where the object4 is currently.  To add some logic, I used Boolean (true/false) values.

          In the click action for object 1, I wrapped the above code in an IF statement:


          if (clicked == true){ sym.getSymbol('object4').playReverse();  clicked = false; }


          and added to the object4 click action:

          clicked = true;


          So now, the code will register that object4 has completed its animation, and when object 1 is clicked, it will play the reverse.  To add this to multiple objects, though, I think could get a bit repetitive, so maybe there's a better way?



          As I said before, I am not an expert, but hopefully this helps.

          1 person found this helpful
          • 2. Re: When I click on a object, I want an other object to return to its original position
            Jnberg Level 1

            Hi, thank you. The code you posted does kind of what I want, but not exactly. Maybe I need an array or something to target multiple objects, but I can't figure out how arrays work.

            I could get around the problem if it's possible to prevent multiple clicks. For example, to play one animation at a time and not be able to click on a new object until the previous animation has finished?