gavin sim logo
 

Basic - week 1

Week 2

Week 3

Week 4

Week 5

Week 6

Week 7

Teaching > Flash notes

Loading an Image

Download horse.jpg

Create a new flash document and rename layer 1 actions, change the size to 700x500. On the actions layer open the actions panel and type:

var ImageRequest:URLRequest = new URLRequest("horse.jpg");
var imageLoader:Loader = new Loader();

imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

imageLoader.load(ImageRequest);

function imageLoaded(event:Event):void{
     addChild(imageLoader);
}

The URLRequest variable represent the location of the external file that will be loaded. The loader is a method that enables the file to be loaded. The imageLoader.load() is a method that is instructing the loader to load the ImageRequest file in this instance horse.jpg. The event listener is listening for the image to have completly loaded and then it will be added to the stage. You then use the addChild to add the item to the display list which is the stage.

Save your file in the same folder you placed the horse.jpg

Control test movie to test the application.

Part 2

Next just before the addChild add the following code:

     imageLoader.x=40;
     imageLoader.y=50;
     

This controls the X and Y position of the imageLoader and will add it to the stage in this position once the addChild method is called.

Control / Test Movie