The code I found below basically caches an image and renders it to the screen with controls for keeping the loaded image smooth.
My problem is the image I tried isn’t registering a width or height, thought the clip is visible, and no errors were given
Can someone tell me why the code below doesn’t effectively center the smiley.png image?
Thanks
// from http://www.kaourantin.net/2005/12/dynamically-loading-bitmaps-with.html
import flash.display.*;
SW = Stage.width;
SH = Stage.height;
function loadBitmapSmoothed(url:String, target:MovieClip) {
// Create a movie clip which will contain our
// unsmoothed bitmap
var bmpMC:MovieClip = target.createEmptyMovieClip("bmpMC", target.getNextHighestDepth());
// Create a listener which will notify us when
// the bitmap loaded successfully
var listener:Object = new Object();
// Track the target
listener.tmc = target;
// If the bitmap loaded successfully we redraw the
// movie into a BitmapData object and then attach
// that BitmapData to the target movie clip with
// the smoothing flag turned on.
listener.onLoadInit = function(mc:MovieClip) {
mc._visible = false;
var bitmap:BitmapData = new BitmapData(mc._width, mc._height, true, 0x44FFFFFF);
this.tmc.attachBitmap(bitmap, this.tmc.getNextHighestDepth(), "auto", true);
bitmap.draw(mc);
mc.removeMovieClip(this);
};
// Do it, load the bitmap now
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmpMC);
}
this.createEmptyMovieClip("myMC", this.getNextHighestDepth());
this.loadBitmapSmoothed("images/smiley.png", myMC);
myMC._x=(SW/2)-(myMC._width/2);
myMC._y=(SH/2)-(myMC._height/2);
trace("myMC._x: " + myMC._x);
trace("myMC._y: " + myMC._y);
trace("myMC._width: " + myMC._width);
trace("myMC._height: " + myMC._height);
trace (this);