PDA

View Full Version : preloader



vxd
February 27th, 2009, 10:11 PM
Hi,

On my Website I have a main swf. The main swf will have buttons to load in external swf. The preloader is on the main swf. If I test the movie and click on the link more than once while it's preloading or click on another link while it's preloading the bytesLoaded will keep adding on each swf's bytes I click on. The bytesTotal doesn't change, it will just equal the first swf I clicked on.

So my question is how do I fix it so when I click on the same link or another link while it preloads the bytesLoaded resets to 0.


Here's the preloader code


mLoader.contentLoaderInfo.addEventListener(Event.O PEN,showPreloader);
mLoader.contentLoaderInfo.addEventListener(Progres sEvent.PROGRESS,showProgress);
mLoader.contentLoaderInfo.addEventListener(Event.C OMPLETE,showContent);

//Connects the buttons and the external swf
function loadSWF(evt:MouseEvent):void {

for (i = 0; i<buttonCount; i++) {
if (evt.target.name == aButtons[i].name) {
//trace(evt.target.name);
index = i;
}
}
mRequest=new URLRequest(aSWF[index]);
mLoader.load(mRequest);

}
/*********************** Preloader **********************/

function showPreloader(evt:Event):void {
addChild(mPreloader); // adds preloader to the stage

}
function showProgress(evt:ProgressEvent):void {
trace("bytes loaded "+ Math.round(evt.bytesLoaded/1000) + "kb")
trace("total bytes " + Math.round(evt.bytesTotal/1000) +"kb")

var percentLoaded:Number = evt.bytesLoaded/evt.bytesTotal;
mPreloader.tLoading.text = Math.round(percentLoaded * 100) + " %"; // shows percentage in textfield (tLoading)

}

function showContent(evt:Event):void {
removeChild(mPreloader); // Remove preloader from stage once all content is loaded
addChild(mLoader); // add Content to stage

}



Thanks

vxd

vxd
February 28th, 2009, 05:54 AM
I've changed the code a little bit and it helped but still not right. i've added mLoader = new Loader() and the event handlers inside the loadSWF function. It doesn't load over 100% now but it is still preload each link I click on. So it's calculating mutliple mLoaders which isn't what I want to do.

Any help will be greatful