Skip navigation
Sam*maS
Currently Being Moderated

Creating Motion Animations using Actionscript

Jan 8, 2013 7:24 PM

So I would like to create something similar to a motion tween in flash using actionscript 3.0 code. I would like it to happen when I press a button.

 

The closest I get is this:

 

flash code.PNG

 

However, this shifts it without a movement. It is an instantaneous change when I would rather have it be actual movement.

 

Can anybody help me?

 

Thank you.

 
Replies
  • kglad
    72,227 posts
    Jul 21, 2002
    Currently Being Moderated
    Jan 8, 2013 7:43 PM   in reply to Sam*maS

    use the Tween class or, even better, use the 3rd party TweenLite (www.greensocks.com).

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 8, 2013 9:04 PM   in reply to Sam*maS

    The easiest way for simple tweens is the built-in class. While I also advocate TweenLite/Nano/Max (greensock.com not greensocks.com) it only really matters when you're doing a large amount of tweens at a time (hundreds or thousands depending on the computer). It also helps that libraries like that let you animate multiple properties in the same line.

     

    If you use Flash's built in code tweens you'll need to make a single new tween per property you want to animate (without getting complicated):

     

    import fl.transitions.Tween;

    import fl.transitions.easing.Regular;

     

    // animate 4 properties on 2 objects, over 1 second

    new Tween(usflag, "x", Regular.easeInOut, usflag.x, (usflag.x -= 100), 1, true);

    new Tween(usflag, "y", Regular.easeInOut, usflag.y, (usflag.y -= 100), 1, true);

    new Tween(russianflag, "x", Regular.easeInOut, russianflag.x, (russianflag.x -= 100), 1, true);

    new Tween(russianflag, "y", Regular.easeInOut, russianflag.y, (russianflag.y += 200), 1, true);

     

    Or if you download and load greensock.com's TweenLite SWC (or source), example:

     

    import com.greensock.TweenLite;

    import com.greensock.easing.Quad;

     

    TweenLite.to(usflag,1,{x:(usflag.x -= 100),y:(usflag.y -= 100),ease:Quad.easeInOut});

    TweenLite.to(russianflag,1,{x:(russianflag.x -= 100),y:(russianflag.y += 200),ease:Quad.easeInOut});

     

    Both systems come with event handlers to let you know when things are complete and much more.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points