Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created May 12, 2009 02:39
Show Gist options
  • Save jubishop/110281 to your computer and use it in GitHub Desktop.
Save jubishop/110281 to your computer and use it in GitHub Desktop.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="applicationComplete(event)" >
<mx:Script><![CDATA[
import mx.events.FlexEvent;
import mx.controls.Image;
import flash.events.Event;
private var imgURL:String = "http://xerto.free.fr/toad1.jpg";
private function applicationComplete(event:FlexEvent):void {
// Add 100 images
for (var i:int = 0; i < 10; i++)
createNewImage();
// Now we'll add one image, and remove one, every frame
addEventListener(Event.ENTER_FRAME, swapImages);
}
// Removes an image, and adds a new one.
private function swapImages(event:Event):void {
removeImage();
createNewImage();
}
// Removes a random image from the display tree
private function removeImage():void {
removeChild(getChildAt(Math.floor(Math.random() * numChildren)));
}
// Adds and randomly places an image in the display tree
private function createNewImage():void {
var image:Image = new Image();
image.source = imgURL;
image.x = Math.random() * stage.stageWidth;
image.y = Math.random() * stage.stageHeight;
addChild(image);
}
]]></mx:Script>
</mx:Application>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment