2 Replies Latest reply on Jan 19, 2015 12:36 AM by mr.monsen

    Problems with switch statement

    mr.monsen

      He everyone,

       

      i tried to built a page with 4 buttons. Each button is a symbol that contains 2 png´2 which are the the button Designs. If you click on  button 1 it should move on the screen. If you click it again it should moves back. and if you click on another button while button1 is active then button1 should move back to starting position and button 2 should move on screen.

       

      i use a switch statement and a variable.

       

      on composition ready i used

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

      to set the Variable

       

      on each button(one of the png inside the symbols) i used:

       

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

      switch (current)

      {

      case "" :

      sym.play("in");

      break;

      case button1 :

      sym.play("out");

      break;

      default :

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

      sym.play("in");

      break;

      }

       

       

      ad each animation of the buttons are labels for the in and out animation. There are also triggers that change the variable current on the stage

       

      sym.getComposition.getStage.setVariable("current","button1");

       

      if i test it inside of a browser and click on one of the button nothing happens.

      i´m not sure what´s my mistake.

      can anyone help me?

      regards

      mr.monsen

        • 1. Re: Problems with switch statement
          joel_pau Level 5

          Hi,

           

          Some syntax errors in red:

           

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

          switch (current)

          {

          case "" :

          sym.play("in");

          break;

          case "button1" :

          sym.play("out");

          break;

          default :

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

          sym.play("in");

          }

           

           

          sym.getComposition().getStage().setVariable("current","button1");

          • 2. Re: Problems with switch statement
            mr.monsen Level 1

            Thank you very much! you made my monday:)

            now it works. got some problems with the symbols. If the composition is played for the first time then some of the symbols are already played. But i solved it trough a statement in CompositionReady:

            sym.getSymbol(symbol).stop(00);

             

            Have a nice day!