import flash.display.BitmapData;
/**
* Class to load images with that will be automatically smoothed, workaround for the Flash Player 8 non smoothing 'feature' for loaded images
* @author Martijn de Visser
* @usage
* <code>
* var loader:ImageLoader = new ImageLoader();
* loader.loadImage( "some_image.jpg", image_mc );
* </code>
*/
class ImageLoader {
private var mLoader:MovieClipLoader;
/**
* Constructor
*/
public function ImageLoader () {
mLoader = new MovieClipLoader();
addListener(this);
}
/**
* Pass along any events from internally used MovieClipLoader
*/
public function addListener ( inListener:Object ) {
mLoader.addListener(inListener);
}
public function removeListener ( inListener:Object ) {
mLoader.removeListener(inListener);
}
/**
* Triggered by MovieClipLoader
*/
private function onLoadInit ( inTarget:MovieClip ) : Void {
// create new BitMap data object and
// draw the loaded bitmap in new bitmap
var bitmap:BitmapData = new BitmapData(inTarget._width,inTarget._height, true, 0x000000);
bitmap.draw(inTarget);
// create a new movieclip to display the bitmap with
var parent:MovieClip = inTarget._parent;
var img:MovieClip = parent.createEmptyMovieClip("imageloader_smooth_mc", parent.getNextHighestDepth());
// remove original bitmap
inTarget.unloadMovie();
inTarget.removeMovieClip();
delete inTarget;
// draw BitMap in new clip, using the 'smoothing' flag
img.attachBitmap(bitmap, img.getNextHighestDepth(),"auto", true);
}
/**
* Starts loading an image.
*/
public function loadImage ( inImage:String, inTarget:MovieClip ) : Void {
// create mc to load bitmap in
var raw:MovieClip = inTarget.createEmptyMovieClip("imageloader_raw_mc", inTarget.getNextHighestDepth());
// start loader
mLoader.loadClip(inImage,raw);
}
/**
* @return Package and class name
*/
public function toString () : String {
return "ImageLoader";
}
}