Hi, I would liek to use this code to load and display images within 4 movie clips. But it looks like this fires off an event for “imageLoaded” which means I can’t specify which movieclip to use (in an arg).
Is there an easy way to make this code reusable for all 4 images?
//Define a loader
var imageLoader:Loader;
function loadThisImage(url:String):void {
//Show Preloader
preloader.visible=true;
imageLoader=new Loader();
imageLoader.load(new URLRequest(url));
//Add a listener to update the preloader on the image's progress
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,imageLoading);
//Adding a listener that will update the preloader once the image has been loaded
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoaded);
}
var thisImage:String;
function imageLoaded(evt:Event):void {
// Load Image by adding it to the display list
ImageLoaderClip.addChild(imageLoader);
// Hide Preloader
preloader.visible=false;
}
function imageLoading(evt:ProgressEvent):void {
// Get the current download progress
var loaded:Number=evt.bytesLoaded/evt.bytesTotal;
// Send progress info to "preloader" movie clip
updateProgress(loaded);
}
function updateProgress(value:Number) {
preloader.progress.width=value*preloader.bar.width;
}
//Loading the image defined in the parameter
loadThisImage("myPic1.png");