hi,
I’ve created a flash banner which loads 3 images. Each image is loaded using a Loader object. Each Loader object has an event listener which points to the same function. In this function I compute the loaded/total bytes, then I update a dynamic TextField.
The problem is that the TextField doesn’t change its text only when all the images are loaded, which means at 100%. I used a trace for percent and it works fine. From what I’ve read until now, it seems that this can be caused by a lock-up of the UI?
Any hint or ideea is appreciated,
Thanks.
The function:
function updatePreloader(e:ProgressEvent):void {
if (LoaderInfo(e.target).loader == imageLoaders[0]) {
loadedBytes1 = e.bytesLoaded;
totalBytes1 = e.bytesTotal;
}
if (LoaderInfo(e.target).loader == imageLoaders[1]) {
loadedBytes2 = e.bytesLoaded;
totalBytes2 = e.bytesTotal;
}
if (LoaderInfo(e.target).loader == imageLoaders[2]) {
loadedBytes3 = e.bytesLoaded;
totalBytes3 = e.bytesTotal;
}
loadedBytes = loadedBytes1 + loadedBytes2 + loadedBytes3;
totalBytes = totalBytes1 + totalBytes2 + totalBytes3;
percent = loadedBytes/totalBytes*100;
if (!isNaN(percent))
pContainer.preloader.percent.text = int(percent)+"%";
}
The Loaders:
for (var i:int=0; i<3; i++) {
imageLoaders* = new Loader();
imageLoaders*.load(new URLRequest(pathBase+_XML.image*.@image_path));
imageContainer["image"+(i+1)].addChild(imageLoaders*);
imageLoaders*.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, updatePreloader);
thumbLoaders* = new Loader();
thumbLoaders*.load(new URLRequest(pathBase+_XML.image*.@thumb_path));
thumbContainer["thumb"+(i+1)].addChild(thumbLoaders*);
var caption:String = new String();
CAPTIONS* = _XML.image*.@caption;
var link:String = new String();
LINKS* = escape(_XML.image*.@link);
}