Ive got a menu on top of my page which has a few buttons. On each button press, I have a standard “_root.pages.gotoAndStop(frame#);” and also a function call which loads a different picture into the background. So, the page appears, and a loader shows “LOADING BACKGROUND” and then once its loaded it fades in overtop of whatever picture was there.
Problem is…if I click the buttons fast (before the background loaded), the pages work fine, but since the background didnt fully load, the correct background for each page seems to get confused and isnt right.
Here’s the function that loads the back pictures…
var fadespeed = 5;
function load_pic(myLoad, myNum:Number) {
//if current page, do nothing
if (_root.prior != myNum) {
var mcLoader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadStart = function(targetMC:MovieClip) {
//set new holder alpha to 0
_root.mc_backpics["img"+ myNum]._alpha = 0;
//bring new holder to top
_root.mc_backpics["img"+ myNum].swapDepths(_root.mc_backpics["img" + _root.prior]);
//show loading progress
_root.backpicloader._visible = true;
};
listener.onLoadProgress = function(targetMC:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
var percent:Number = Math.round(bytesLoaded/bytesTotal*100);
_root.backpicloader.text = percent;
};
listener.onLoadInit = function(targetMC:MovieClip) {
//set size of new background pic
_root. mc_backpics["img"+myNum].myPic._height = System.capabilities.screenResolutionY;
_root. mc_backpics["img"+myNum].myPic._width = System.capabilities.screenResolutionX;
_root.backpicloader._visible = false;
targetMC.onEnterFrame = function() {
//when loaded, fade in
if (targetMC._alpha<100) {
targetMC._alpha += fadespeed;
} else {
//when finished fading in, set previous photo and previous previous
_root.minusone = _root.prior
_root.prior = myNum;
delete targetMC.onEnterFrame;
if (_root.minusone != _root.prior) {
//prevent old images from reappearing when alpha fades
_root. mc_backpics["img"+minusone]._alpha = 0;
//no longer need img0 after img1 is loaded
_root.mc_backpics.img0._visible = false;
}
}
};
};
mcLoader.addListener(listener);
mcLoader.loadClip(myLoad,_root.mc_backpics["img"+myNum]);
}
};
Ive heard that you cant cancel the loading of a swf… I dont care if it keeps loading but Id maybe like to set up a listener or implement some code that just checks to make sure the correct picture is being displayed at all times and if its not, load that one.
Thanks!
Rich