Hi all.
I have been working on my online portfolio lately and ran into a problem which I initially thought I had solved.
I had been loading dynamic images from an XML file into an empty MC using the ‘loadMovie’ function. No problems. I even had them preloading nicely using a preloader and a bit of script.
However, I wanted to be able to rotate these images, and when I did, they lost their quality. I found this was actually an issue with Flash and that it does not by default smooth externally loaded images.
To solve this, I found the below workaround script online:
import flash.display.*;
function loadBitmapSmoothed(url:String, target:MovieClip) {
// Create a movie clip which will contain our
// unsmoothed bitmap
var bmc:MovieClip = target.createEmptyMovieClip(
"bmc",
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);
this.tmc.attachBitmap(
bitmap,
this.tmc.getNextHighestDepth(),
"auto",
true);
bitmap.draw(mc);
};
// Do it, load the bitmap now
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
}
This code works well, when used in place of the ‘loadMovie()’ function. I can rotate my dynamically loaded images and they retain their quality/smoothness.
However, the issue I have run into now is that my preloader no longer works with this new code.
Here’s the AS for my preloader, where ‘imageLoader_mc’ is my MC and
‘preloader_mc’ is my preloader:
this.onEnterFrame = function() {
filesize = Math.floor(imageLoader_mc.getBytesTotal());
loaded = Math.floor(imageLoader_mc.getBytesLoaded());
if (loaded != filesize) {
preloader_mc._alpha = 100;
preloader_mc._rotation += 10;
imageLoader_mc._alpha = 0;
} else {
preloader_mc._alpha = 0;
if (imageLoader_mc._alpha<=100) {
imageLoader_mc._alpha += 20;
}
}
};
I think the issue is that the ‘getBytesTotal()’ and ‘getBytesLoaded()’ functions do not work with the ‘loadBitmapSmoothed()’ function.
Problem is, I don’t know how to edit the code to allow the preloader to work.
I was wondering if anyone may be able to help me out with this?
Thanks so much,
Enforcer73