Here 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;
}
}
}
}
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.