Sup, guys. I’m designing a portfolio website that will showcase artwork that could potentially take awhile to load, so I’m using the code from that tutorial:
var imageLoader:Loader;
function loadImage(url:String):void {
preloader.visible = true;
// Set properties on my Loader object
imageLoader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
loadImage("azuredragon.png");
function imageLoaded(e:Event):void {
// Load Image
imagearea.addChild(imageLoader);
preloader.visible = false;
}
function imageLoading(e:ProgressEvent):void {
// Get current download progress
var loaded:Number = e.bytesLoaded / e.bytesTotal;
// Send progress info to "preloader" movie clip
preloader.SetProgress(loaded)
// Use it to get current download progress
// Hint: You could tie the values to a preloader :)
}
I’m using one of these, one image, per frame. I’ll be adding more and more in the future. I’m still a newbie to as3 and I haven’t completely understood the basics yet, so my question is this: how do I reuse the above code for a different frame without having to paste the entire thing with different names? I tried this:
trace(imageLoader);
loadImage("colorfulserpent.png");
imageLoaded();
imageLoading();
Of course, it didn’t work. Help?