5 Replies Latest reply on Aug 11, 2014 9:06 AM by subbbace

    hello, code is difficult ..

    Shlomiii

      hey so i have a question.

       

      i'm trying to create a button which when you click it moves and when you click again on him he moves back.

       

      in the code panel i cant find any "second click" action

       

      any suggestions ?

       

      thnx !

        • 1. Re: hello, code is difficult ..
          Robyn_cpl Level 2

          Hi,

           

          If you use variables to say if click =0 play move (then add 1)

          then

          if click =1 play move back

          • 2. Re: hello, code is difficult ..
            Robyn_cpl Level 2

            Add a trigger at the very beginning of the stage timeline or the stage composition ready and add this

             

            sym.setVariable"(count_click", 0);

            //this is setting a variable from the start

             

            then on your click code have this

             

            var count_click = sym.getVariable("count_click");

            //this is getting the value of the variable

            if (count_click ==0)

            {

                 PLAY MOVE HERE

                 sym.setVariable("count_click", 1);

            }

            //this is saying if the count is 0 play X then change the count to 1

            else if (count_click ==1)

            {

                 PLAY MOVE BACK HERE

                 sym.setVariable("count_click", 0);

            }

            //and this is saying else if the count is 1 play X and change the count back to 0




            If there is more than just 2 clicks there is other bits of code that allows you to have infinite about of clicks.

             

            I hope this helps

            1 person found this helpful
            • 3. Re: hello, code is difficult ..
              subbbace Level 1

              i found an easy way for this.. to make a second button ,create an invisible square/div.then animate it to it pop infront  of the button you clicked when it moves to the second click position, then code it ,so when you click the invisible square overtop of the clickable button, it will reverse the timeline back to the first position. then animate the button to pop out of the screen while the button moves back to first position..easy to do with out getting code confusion .lol

               

              you can do it with in the symbol or on the timeline..but with in the symbol is best so you don't have invisible buttons popping up in your scene.lol

              1 person found this helpful
              • 4. Re: hello, code is difficult ..
                Robyn_cpl Level 2

                Using the code I have added in the above comment makes more sense than adding another div.

                 

                This becomes a problem if you do this for every click, since you will have div's all over the place and trying to keep track of them.

                 

                If the clickable item is the symbol that is being animated then using that code is very simple!

                 

                I've been using that type of code for navigation buttons and loads of other stuff that has more than one click and its much more manageable than adding invisible boxes that you will have to turn on and off when you need/don't need them.

                • 5. Re: hello, code is difficult ..
                  subbbace Level 1

                  i have no problem and i can do more things using my way.  www.trebaltek.ca   but ya dosnt really matter.what ever does the trick.but organization is the key.if you know how to organize your files off the stage properly you should never have that problem,also dont make the boxes invisible untill your done programming them.