4 Replies Latest reply on Mar 1, 2016 10:12 AM by rbencz

    change Boolean variable on the stage

    rbencz

      hi! this is my first post here! so I've been playing around for a while with the Adobe Edge Animate for a while and it's pretty cool and I'm trying to create a super basic layout with a looping video, and when the user press the button, the current video plays until the end and then starts the new one. the button simply it changes the the variable state from false to true, pretty straight forward but for some reason it's not working. I'm an artist, so I don't know much about code besides if/else haha

       

      here is the code on the stage (it's set on the CompositionReady):

       

      var loop1 = sym.$("loop")[0];
      
      var nextLoop = new Boolean();
      console.log(nextLoop); //false
      
      loop1.onended = function(e){
      if (nextLoop == true){
           // Show an element
           sym.$("loop2").show();
           // Play a video track
           sym.$("loop2")[0].play();
           }
           else{
           loop1.play()
           }
      };
      
      

       

      and here's the button code:

       

      sym.getSymbol("next_btn").play(); //fade out
      //change nextLoop state
      sym.getComposition().getStage().nextLoop = true;
      
      

       

      I'm pretty much sure it's a syntax error, but I really don't know how to fix it

       

      any ideas?

       

      thanks in advance!

        • 1. Re: change Boolean variable on the stage
          ddhayles Level 3

          Hi rbencz

           

          You will need to create a global variable for it to function correctly, I have commented the 2 lines I have added:

           

          sym.setVariable("nextLoop", false); // Create a new global variable called 'nextLoop' and set it to false

           

          var loop1 = sym.$("loop")[0];

           

          loop1.onended = function(e){

            nextLoop = sym.getComposition().getStage().getVariable("nextLoop"); // Get Global Variable and set it to a local variable

            if (nextLoop == true){

              // Show an element

              sym.$("loop2").show();

              // Play a video track

              sym.$("loop2")[0].play();

            } else {

              loop1.play()

            }

          };

           

          And then on your button place the following code:

           

          sym.getComposition().getStage().setVariable("nextLoop", true); // Change the value of the global variable 'nextLoop' to true

          • 2. Re: change Boolean variable on the stage
            rbencz Level 1

            yes!! it works like a charm, thank you so much!!

             

            so anytime I need to modify an variable I've to use the "setVariable", pick the variable's name and change it's value, is that right?

            • 3. Re: change Boolean variable on the stage
              ddhayles Level 3

              No Worries, so first you need to declare the variable as a global before you do anything else at document.compositionready using sym.setVariable()

              i.e.

              sym.setVariable("nextLoop", false); // Creates a new global variable called 'nextLoop' and set it to false


              You can then assign that global to a local variable anywhere you like, inside any symbol, at any level by using getVariable() and targeting it on the root sym.getComposition().getStage().

              i.e.

              nextLoop = sym.getComposition().getStage().getVariable("nextLoop"); // Gets the Global Variable and set it to a local variable

               

              Then whenever you need to change the Global variable you can target the original path of the first variable you set using the setVariable() again:

              i.e.

              sym.getComposition().getStage().setVariable("nextLoop", true); // Change the value of the global variable 'nextLoop' to true or false


              Hope that helps.

              • 4. Re: change Boolean variable on the stage
                rbencz Level 1

                got it!! thanks a lot for the help!