2 Replies Latest reply on Oct 10, 2012 12:09 AM by mobly

    button script help

    mobly Level 3

      http://blogs.adobe.com/edge/2012/07/18/tutorial-leveraging-independent-symbol-timelines/#c omment-501

       

      Hi Guys

      I was going through the sliding button examples in the tutorial files, and wanted to try to modify it, but seriously failing due to severe lack of knowledge of javascript.

       

      so the example (see link above) has 3 buttons red, blue and green that creates an animation slide in and out

      but if the red magazines slide in and the user clicks the red button again the red magazines animate again, not so good IMO.

      So can I get help to add a couple of line to say if I'm at the end of the red animation then stay here if clicked.

      My pathetic attempt below in bold was on the basis that I added a label called "end" at the end of the animation, so was trying to say if I'm at "end" then stop ie do nothing, but it doesnt work :-(

       

      Any help?

      Thanks very much

       

       

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

      if (current != "") {

         sym.getSymbol(current).play("out");

         sym.getSymbol("red").play("in");

      }

       

       

      if (current != "end") {

         sym.getSymbol(current).stop;

      }

       

      else {

         sym.getSymbol("red").play("shortIn");

      }

      sym.setVariable("current", "red");

        • 1. Re: button script help
          jbowden Adobe Employee

          Hi there,

           

          The approach you've taken above won't work for a few reasons: you haven't set the variable current to "end", and if you did, it still wouldn't work because the first test checks to see if the variable current is an empty string (""). The other is a syntax error - stop is a method and should be followed by parenthesis, e.g., sym.getSymbol(current).stop();

           

          If you don't want to play the symbol animation again when you click the same button again, you instead tweak the conditional statement (if/else) just a little bit to test for that condition, and if you find it, exit the rest of that block of code before it ever executes. Something like this:

           

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

           

          if (current == "red") {

               // if the button has already been clicked and you are clicking it again

                    return // exit the rest of this conditional code

          }

          else if (current != "") {

               // if a button, but not this one, has already been clicked

             sym.getSymbol(current).play("out");

             sym.getSymbol("red").play("in");

          }

          else {

             sym.getSymbol("red").play("shortIn");

          }

           

          sym.setVariable("current", "red");

           

          Apply this change to the same code in each button, but test for the correct color in each one, e.g. if (current == "blue"), etc. and you should be good to go.

           

          hth,

          Joe

          • 2. Re: button script help
            mobly Level 3

            Hi Joe

            Thank you very much for taking the time to help and explain so well. I think I need to sign up for some lynda.com training courses! Basic ones too!!

            cheers

            Alistair