Hi, I have this very simple ImageLoader class:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.display.Loader;
public class ImageLoader extends MovieClip {
var imageLoader:Loader;
public function ImageLoader(img:String)
{ loadAsset(img); }
public function loadAsset(url:String):void {
//warning here
preloader.visible = true;
imageLoader = new Loader();
imageLoader.load(new URLRequest(url)); imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); } //;
public function imageLoaded(evt:Event):void {
//warning here
imageLoaderClip.addChild(imageLoader);
preloader.visible = false; } //
public function imageLoading(evt:ProgressEvent):void {
var loaded:Number = evt.bytesLoaded / evt.bytesTotal; updateProgress(loaded); }
public function updateProgress(value:Number) {
preloader.progress.width = value * preloader.bar.width;
} } }
This works perfectly if this is the DocumentClass.
BUT, if instead the DocumentClass is like this one:
package {
import flash.display.MovieClip;
public class LoadTest extends MovieClip
{
public function LoadTest()
{var img = new ImageLoader(“DSC04550.JPG”); }
}
}
this doesn’t work anymore, because of the presence of the stage movieclips “preloader” and “imageLoaderClip”.
Which is the most common way to make the things work? I thought to pass a reference to the ImageLoader class as a parameter (eg I pass the preloader and the movieclip that loads the images). Is there any other (and better) way when dealing with situations like this one? Thank you!