I have played around with the Dynamically Loading Bitmaps With Smoothing
from Tinic Uro as well as somme other advices from people on the kirupa forum.
The code works great. I am trying to load different Bitmaps, fullscreen, on the click of a button (or any other event). The images load, but they just stack on top of each others and thus, they don’t resize to the stage properly. Here is the code with the attached FLA:
( you’ll need 3 jpg named bg1.jpg, bg2.jpg, bg3.jpg, all in the same folder as the fla)
stop();
Stage.scaleMode = "noScale";
Stage.align = "LT";
Stage.addListener(this);
bg_con._x = 0;
bg_con._y =0;
bg_con._width = (Stage.width/2)-(target._width/2);
bg_con._height = (Stage.height/2)-(target._height/2);
import flash.display.*;
function loadBitmapSmoothed(url:String, target:MovieClip) {
var bmc:MovieClip = target.createEmptyMovieClip("bmc", target.getNextHighestDepth());
var listener:Object = new Object();
listener.tmc = target;
listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
percent = Math.round((bytesLoaded/bytesTotal)*100);
pText.text = percent+"%";
};
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);
// set size and position on load
if (Stage.height/Stage.width>target._height/target._width) {
img_prop = target._width/target._height;
target._height = Stage.height;
target._width = Stage.height*img_prop;
target._y = (Stage.height/2)-(target._height/2);
target._x = (Stage.width/2)-(target._width/2);
} else {
img_prop = target._height/target._width;
target._width = Stage.width;
target._height = Stage.width*img_prop;
target._y = (Stage.height/2)-(target._height/2);
target._x = (Stage.width/2)-(target._width/2);
}
};
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
}
var stage_listener:Object = new Object();
stage_listener.onResize = function():Void {
if (Stage.height/Stage.width>bg_con._height/bg_con._width) {
img_prop = bg_con._width/bg_con._height;
bg_con._height = Stage.height;
bg_con._width = Stage.height*img_prop;
bg_con._y = (Stage.height/2)-(bg_con._height/2);
bg_con._x = (Stage.width/2)-(bg_con._width/2);
} else {
img_prop = bg_con._height/bg_con._width;
bg_con._width = Stage.width;
bg_con._height = Stage.width*img_prop;
bg_con._y = (Stage.height/2)-(bg_con._height/2);
bg_con._x = (Stage.width/2)-(bg_con._width/2);
}
};
Stage.addListener(stage_listener);
loadBitmapSmoothed("bg1.jpg", bg_con);
btn1.onRelease = function () {
loadBitmapSmoothed("bg1.jpg", bg_con);
};
btn2.onRelease = function () {
loadBitmapSmoothed("bg2.jpg", bg_con);
};
btn3.onRelease = function () {
loadBitmapSmoothed("bg3.jpg", bg_con);
};
Then I have found another code to load bitmap fullscreen dynamically, it works, the pictures doesn’t stack, but the images are not smooth! How could I combine this with the loadbitmatsmoothed?
Stage.scaleMode = "noScale";
Stage.align = "LT";
stage.quality = StageQuality.BEST;
_root.container._highquality = 2;
my_mc = new MovieClipLoader();
preload = new Object();
my_mc.addListener(preload);
preload.onLoadStart = function(targetMC) {
container._visible = false;
pText._visible = true;
};
preload.onLoadProgress = function(targetMC, lBytes, tBytes) {
bar._width = (lBytes/tBytes)*100;
pText.text = "% "+Math.round((lBytes/tBytes)*100);
};
preload.onLoadInit = function(targetMC) {
container._visible = true;
pText._visible = false;
if (Stage.height/Stage.width>targetMC._height/targetMC._width) {
mc_prop = targetMC._width/targetMC._height;
targetMC._height = Stage.height;
targetMC._width = Stage.height*mc_prop;
targetMC._y = (Stage.height/2)-(targetMC._height/2);
targetMC._x = (Stage.width/2)-(targetMC._width/2);
} else {
mc_prop = targetMC._height/targetMC._width;
targetMC._width = Stage.width;
targetMC._height = Stage.width*mc_prop;
targetMC._y = (Stage.height/2)-(targetMC._height/2);
targetMC._x = (Stage.width/2)-(targetMC._width/2);
}
};
var stage_listener:Object = new Object();
stage_listener.onResize = function():Void {
if (Stage.height/Stage.width>container._height/container._width) {
mc_prop = container._width/container._height;
container._height = Stage.height;
container._width = Stage.height*mc_prop;
container._y = (Stage.height/2)-(container._height/2);
container._x = (Stage.width/2)-(container._width/2);
} else {
mc_prop = container._height/container._width;
container._width = Stage.width;
container._height = Stage.width*mc_prop;
container._y = (Stage.height/2)-(container._height/2);
container._x = (Stage.width/2)-(container._width/2);
}
};
Stage.addListener(stage_listener);
loadBitmapSmoothed("reposado.jpg", "container");
//load the mc
my_mc.loadClip("bg1.jpg", "container");
btn1.onRelease = function () {
my_mc.loadClip("bg1.jpg", "container");
};
btn2.onRelease = function () {
my_mc.loadClip("bg.2jpg", "container");
};
That would be sweet if the images could do a crossfade as they load! but I’ll play with this only when I solve the current problem… unless somebody has a solution.
thanks