7 Replies Latest reply on Jan 19, 2016 11:44 AM by resdesign

    Problem with "if - else if" statement with mouse click.

    jdhughen

      I'm having a problem with  IF ELSE code use with a mouse click. What I want each time a user "clicks" i want to execute a particular block of code, up to 3 clicks, then nothing. I've tried local and global click counter var but can't seem to get past the first "if". This is what I have now (I'm using console.log() to keep track.

       

      In comp ready i create a global var ...

       

      // insert code to be run when the composition is fully loaded here
      sym.getComposition().getStage().setVariable('clickcnt', 1); //set counter to 1

      var i = sym.getComposition().getStage().getVariable('clickcnt');

      console.log ("Counter is starting at "+i);


       

      on the stage i create a "click" event..

       

      // insert code for mouse click here
      var i = (sym.getComposition().getStage().getVariable('clickcnt');
        if (i=1){
           console.log("counter is = "+i);
           //do some code
      sym.getComposition().getStage().setVariable('clickcnt', 2); //set counter to 2
        }
      else if (i=2){
           console.log("counter is = "+i);
           //do some code
           sym.getComposition().getStage().setVariable('clickcnt', 3);
      //set counter to 3
        }
      else if (i=3){
           console.log("counter is = "+i);
            //do some code
            sym.getComposition().getStage().setVariable('clickcnt', 4);
      //set counter to 4 taking it out of range
            sym.play(100); //play the timeline animation
        }
      else {  //I'm using this to negate any further clicks. I'm sure there's a proper way to do this. I just don't know it.
      sym.stop(1000);
      console.log("end");
      }
      ;

       

      I When I run this It never gets passed the first if, It's like the "clickcnt" var is not getting updated or read properly.

      thanks

       

      Joel H