3 Replies Latest reply on Jan 4, 2017 9:13 AM by Tonyteach

    How to Update a Global Variable on a Symbols Timeline

    Tonyteach

      I’ve declared a Global Variable on the Stage

       

       

      sym.setVariable("taste", "water"); // My global variable for the wine

       

       

      Then, on my symbol’s timeline, I have triggers to change the variable:

       

       

      sym.getComposition().getStage().setVariable("taste", "NO THANKS"); // 0 ms

       

       

      sym.getComposition().getStage().setVariable("taste", "Occasionally"); // 432ms

       

       

      sym.getComposition().getStage().setVariable("taste", "I Love It!"); // 1360 ms

       

       

      I have a button to check the status of the variable:

      on click

      var tastevar = sym.getComposition().getStage().getVariable("taste");

      alert(tastevar);

       

       

      but the variable doesn’t update consistently, if at all.

       

      Any thoughts?

      Here is a link to the file if needed: Dropbox - wine_5a.zip

        • 1. Re: How to Update a Global Variable on a Symbols Timeline
          ddhayles Level 3

          Hi Tonyteach

           

          I can't see any errors in our code, also I have run you EA project and it seems to be working fine for me.

           

          The only thing I can think of is that when you click on the "results" button after you have moved your scroller then scroller didn't initiate the trigger point, i.e. when you are scrolling through the timeline not every frame is triggered so it may have skipped over your trigger point.

           

          What may be better to do is on your results button run a script that looks at when the playhead is on the timeline. i'll see if I can write you something that may work.

          • 2. Re: How to Update a Global Variable on a Symbols Timeline
            ddhayles Level 3

            Try this, it uses a number for the timeline rather than the table but it works just as well:

             

            var currentPosition = this.getPosition();

             

            if (currentPosition < 1000) {

              sym.getComposition().getStage().setVariable("taste", "NO THANKS");

            } else if (currentPosition >= 1000 && currentPosition < 2000) {

              sym.getComposition().getStage().setVariable("taste", "Occasionally");

            } else if (currentPosition == 2000) {

              sym.getComposition().getStage().setVariable("taste", "I Love It!");

            }

             

            var tastevar = sym.getComposition().getStage().getVariable("taste");

            alert(tastevar);

            • 3. Re: How to Update a Global Variable on a Symbols Timeline
              Tonyteach Level 1

              Got it to work. This is what I did (let me know if I missed the mark)

              I placed my "if then" on the timelinePlay symbol, actions layer, under a Stop…

              Then changed the numbers:

               

              var currentPosition = this.getPosition();

               

               

              if (currentPosition < 583) {

                sym.getComposition().getStage().setVariable("taste", "no thanks");

              } else if (currentPosition >= 583 && currentPosition < 1493) {

                sym.getComposition().getStage().setVariable("taste", "Occasionally");

              } else if (currentPosition <= 1500) {

                sym.getComposition().getStage().setVariable("taste", "I Love It!");

              }else if (currentPosition == 2000) {

                sym.getComposition().getStage().setVariable("taste", "I Love It!");

              }