4 Replies Latest reply on Jan 12, 2011 9:22 AM by Lee Burrows

    how to use this example code in Flash AS3?

    learner_7n Level 1

      Hi,

       

      How can I use this AS3 code in my Flash CS4 document? The following code is in the below link:

       

       

      http://pv3d.org/2009/12/18/tweenmax-tweening-a-timeline-advanced-tweening/#

       

       

      Please help.

       

      Thanks.

        • 1. Re: how to use this example code in Flash AS3?
          Ned Murphy Adobe Community Professional & MVP

          Search Gppgle using "AS3 Class tutorial" and learn how to use custom classes

          • 2. Re: how to use this example code in Flash AS3?
            Lee Burrows Level 4

            create a new fla in CS4 and set the document class to "EasingATimeline".

             

            next, save the linked code as "EasingATimeline.as" in the same folder as your .fla file

             

            now test movie or publish and it should work

            • 3. Re: how to use this example code in Flash AS3?
              learner_7n Level 1

              Hi,

               

              It is working quite nice. I want to use the same code but instead of as "Document Class" I want to put that code in a first key frame of my project. I tried the following but gets an error:

               

              The error is : 1131: Classes must not be nested.

               

              And the following code  I tried is:

               

                  import com.greensock.TimelineMax;
                  import com.greensock.TweenMax;
                  import com.greensock.easing.Linear;
                  import com.greensock.easing.Quart;

                  import flash.display.Sprite;

                  /**
                   * @author John Lindquist
                   */
                  [SWF(width="900", height="480", frameRate="31")]
                  class EasingATimeline extends Sprite
                  {
                      private var square:Sprite;
                      private static const STEP_DURATION:Number = 1;

                      public function EasingATimeline()
                      {
                          square = new Sprite();
                          square.graphics.beginFill(0xcc0000);
                          square.graphics.drawRect(0, 0, 50, 50);
                          square.graphics.endFill();

                          square.x = 100;
                          square.y = 50;

                          addChild(square);

                          //set all the eases of your steps to Linear.easeNone
                          var step1:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 700, y: 50, ease: Linear.easeNone});
                          var step2:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 700, y: 350, ease: Linear.easeNone});
                          var step3:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 100, y: 350, ease: Linear.easeNone});
                          var step4:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 100, y: 50, ease: Linear.easeNone});

                          var timeline:TimelineMax = new TimelineMax();
                          timeline.append(step1);
                          timeline.append(step2);
                          timeline.append(step3);
                          timeline.append(step4);
                          //pause your timeline
                          timeline.pause();

                          //tween your timeline with whatever ease you want
                          TweenMax.to(timeline, timeline.totalDuration, {currentTime: timeline.totalDuration, ease: Quart.easeInOut, repeat: -1});
                      }
                  }

               

               

              Please help me to solve this problem.

               

              Thanks.

              • 4. Re: how to use this example code in Flash AS3?
                Lee Burrows Level 4

                try this:

                 

                import com.greensock.TimelineMax;

                import com.greensock.TweenMax;

                import com.greensock.easing.Linear;

                import com.greensock.easing.Quart;

                 

                var square:Sprite;

                const STEP_DURATION:Number = 1;

                 

                square = new Sprite();

                square.graphics.beginFill(0xcc0000);

                square.graphics.drawRect(0, 0, 50, 50);

                square.graphics.endFill();

                square.x = 100;

                square.y = 50;

                addChild(square);

                 

                var step1:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 700, y: 50, ease: Linear.easeNone});

                var step2:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 700, y: 350, ease: Linear.easeNone});

                var step3:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 100, y: 350, ease: Linear.easeNone});

                var step4:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 100, y: 50, ease: Linear.easeNone});

                 

                var timeline:TimelineMax = new TimelineMax();

                timeline.append(step1);

                timeline.append(step2);

                timeline.append(step3);

                timeline.append(step4);

                timeline.pause();

                 

                TweenMax.to(timeline, timeline.totalDuration, {currentTime: timeline.totalDuration, ease: Quart.easeInOut, repeat: -1});