4 Replies Latest reply on Aug 7, 2013 3:39 PM by juicy_life

    Play animation until position defined by variable (Was:Play until...)


      I wonder if there is a better way than the code below to play an animation until reaches a position defined by a variable.


            Symbol.bindTimelineAction(compId, symbolName, "Default Timeline", "update", function(sym, e) {

                // insert code to be run on every tick of the timeline here.

                // Be careful not to block or do too much work!


                //get the value of a Symbol variable

                var myVariable = sym.getVariable("myVariableName");


                //check if playhead position reached my Symbol variable

                //must use >= not == to ensure it works

                if (sym.getPosition() >= myVariable) {




      Note the code must be in the "update" timeline event to work, but I don't like much to do that. "Stop at" method doesn't work the same way cause it just moves the playhead position instantly, so the animation doesn't run at all.


      I miss one more optional parameter in the "Play from" and "Play Reverse from" methods to determine an interval to play. Something like...


      sym.play ( start, finish, executeTriggers )


      sym.playReverse ( start, finish, executeTriggers )

        • 1. Re: Play until...
          elainecc Adobe Employee

          Hi, juicy_life-


          Is there a set distance you want to go, or is it completely variable?





          • 2. Re: Play until...
            juicy_life Level 1

            It is variable. I can't use any fixed label in the timeline.


            Imagine you animate a progress bar by streching its width from 0% to 100% in 1 second. Now, you want to be able to stop the progress bar depending on a variable's value.

            • 3. Re: Play until...
              YOSHIOKA Ume Level 3

              Hi, juicy_life, elaine-san.

              In this case, How about using the setTimeout()?

              var targetSym = sym;
              var start = 1000;
              var finish = 1500;
              setTimeout(targetSym.stop.bind(targetSym), Math.abs(finish - start));
              targetSym.play(start); //or targetSym.playReverse(start)
              //case of need adjustment
              //setTimeout(targetSym.stop.bind(targetSym), Math.abs(finish - start), finish);

              Because it's a "timer processing", so troubled if it's stopped on the way.

              but, case of short-time animation, may be O.K.




              1 person found this helpful
              • 4. Re: Play until...
                juicy_life Level 1

                Nice way around the problem. Visual results a bit unpredictable, but with the adjustment option they are solved decently. It's a good option to consider though. Thanks.