[COLOR=#333333]Hi everyone…[/COLOR]
[COLOR=#333333]i have this code:[/COLOR]
**[COLOR=#FF0000]// i have nine buttons that activate doclick function[/COLOR]
for(var i:uint=1;i<=numeroFoto;++i) {
this[“bt”+i].addEventListener(MouseEvent.CLICK,doClick(i));
}
**[COLOR=#FF0000]// the function removes old image listeners, unloads it ,removes child and activates loadMv [/COLOR]
function doClick(imgNum:uint):Function {
return listener;
function listener(e:MouseEvent):void {
if (caricatoreFoto != null) {
caricatoreFoto.contentLoaderInfo.removeEventListen er(ProgressEvent.PROGRESS, caricatoreFotoProgress);
caricatoreFoto.contentLoaderInfo.removeEventListen er(Event.OPEN, caricatoreFotoStart);
caricatoreFoto.contentLoaderInfo.removeEventListen er(Event.COMPLETE, caricatoreFotoComplete);
caricatoreFoto.contentLoaderInfo.removeEventListen er(Event.UNLOAD, caricatoreFotoUnloaded);
}
trace(“Unloading and removing process started…”);
caricatoreFoto.contentLoaderInfo.addEventListener( Event.UNLOAD, caricatoreFotoUnloaded);
caricatoreFoto.unloadAndStop()
removeChild(caricatoreFoto)
caricatoreFoto=null
var mySwf = imgNum
loadMv(“foto”+mySwf);
}
}
**[COLOR=#FF0000]// this function loads the new image [/COLOR]
function loadMv(mySwfNametring):void {
req = new URLRequest( mySwfName + “.png” );
trace("Detected movie to load: " + mySwfName + “.png” );
caricatoreFoto = new Loader();
caricatoreFoto.contentLoaderInfo.addEventListener( Event.OPEN, caricatoreFotoStart);
caricatoreFoto.contentLoaderInfo.addEventListener( Event.INIT, posizionacaricatoreFoto);
caricatoreFoto.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, caricatoreFotoProgress);
caricatoreFoto.contentLoaderInfo.addEventListener( Event.COMPLETE, caricatoreFotoComplete);
caricatoreFoto.load(req);
addChild(caricatoreFoto);
trace("Movie " + mySwfName + “.png is being loaded”);
}
**[COLOR=#FF0000]// no mind about the following code… [/COLOR]
function posizionacaricatoreFoto (e:Event):void{
caricatoreFoto.contentLoaderInfo.removeEventListen er(Event.INIT, posizionacaricatoreFoto)
larghezzacaricatoreFoto=(caricatoreFoto.width)
caricatoreFoto.x=(stageWidth-larghezzacaricatoreFoto)/2
caricatoreFoto.y= posizioneYcaricatoreFoto
trace (“caricatoreFoto.X=”+ (stageWidth/2-larghezzacaricatoreFoto/2))
}
function caricatoreFotoStart(e:Event):void {
prel_mc.visible = true;
preltxt_txt.visible = true;
}
function caricatoreFotoProgress(erogressEvent):void {
var total = e.bytesTotal;
var loaded = e.bytesLoaded;
var percent = Math.round(loaded * 100 / total);
prel_mc.scaleX=percent/100
preltxt_txt.text = String(percent) + “%”;
trace(loaded + " / " + total + " = " + percent);
}
function caricatoreFotoComplete(e:Event):void {
prel_mc.visible = false;
preltxt_txt.visible = false;
trace(“Loading complete”);
}
function caricatoreFotoUnloaded(e:Event):void {
loaded = 0;
trace(“Content has been unloaded and ‘loaded’ variable is set to 0”);
}
in the photoloader if you load a new photo (pushing the botton) when the previous one has completely loaded, there’s no problem…
but if you load a new photo while the previous loading is not complete, the system goes slowly, it seems that the LOADER.unloadAndStop and LOADER.removeChild is unuseful in that case, and the previous photo is still in the cache…
I dont want just disable buttons during loading process (easy solution), but i’d like to solve the problem really unloading the image before a new one is loaded.
Sorry for bad english
Thanks********