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
Excercise
Locate another image from your N: drive or the web and place this in the same location as the horse.jpg. Then in the fla create a button so that when that is pressed the horse will load and be displayed. When the button is pressed a second time the other image will load, this will loop so that the 3rd time the horse will load again.
