08Jan
[AS 3] Simple Tween Animation with Actionscript
No commentsHere is some code that will load an external image and then animate it across the Flash stage. There is an if conditional to check if it rolls off the stage and if it does then animation will play again at original starting point.
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
public class SimpleTween extends Sprite
{
private var image:Loader = new Loader();
private var startingXPoint:uint = 10;
private var startingYPoint:uint = 10;
public function SimpleTween()
{
init();
}
private function init():void
{
// load the image
addChild(image);
image.load(new URLRequest("/path/to/my/image.gif"));
// position the image
image.x = startingXPoint;
image.y = startingYPoint;
// animate the image onEnterFrame
image.addEventListener(Event.ENTER_FRAME, timeline);
}
private function timeline(event:Event):void {
if ( image.x < stage.stageWidth + (image.width/2) && image.y < stage.stageHeight + (image.height/2))
{
// move the image
image.x+= 10;
image.y+= 10;
}
else
{
// this is to reset the image as it is off the screen
image.x = startingXPoint;
image.y = startingYPoint;
}
}
}
}
Categories: Actionscript 3, Animation Transitions
Tuesday, January 8th, 2008 at 11:05 am and is filed under Actionscript 3, Animation Transitions. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.