-
donwloading multiple images/files
Lets say I'm downloading multiple files like this:
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Progre ssEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event. COMPLETE, onLoaderReady);
for(var i =0; i < 100;i++){
var fileRequest:URLRequest = new URLRequest(aImages[i].url);
myLoader.load(fileRequest);
public function
onProgressStatus(e:ProgressEvent) {
// this is where progress will be monitored
trace(e.bytesLoaded, e.bytesTotal);
}
public function onLoaderReady(e:Event) {
// the image is now loaded, so let's add it to the display tree!
someMC.addChild(myLoader);
}
Now the question is how do I tell which image has loaded in the onLoaderReader function, is there a way to identify the image loaded?
-
dont do it like so..
load one image and when its loaded call load again on the next image, until all are loaded
-
-
That code won't even compile. You have an unclosed for loop.
I'd suggest using a package that's already developed for loading a lot of resources, such as bulkloader or queueloader. But if you don't want to deal with those, you'll need to have a new Loader for each resource, or do them one at a time. Assuming you want to load them all at once, you can write a function to create a new loader and kick it off.
Code:
public function loadSomething(url:String):void{
var myLoader:Loader = new Loader();
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
var fileRequest:URLRequest = new URLRequest(url);
myLoader.load(fileRequest);
}
public function onProgressStatus(e:ProgressEvent) {
// this is where progress will be monitored
trace(e.bytesLoaded, e.bytesTotal);
}
public function onLoaderReady(e:Event) {
// the image is now loaded, so let's add it to the display tree!
someMC.addChild(LoaderInfo(e.currentTarget).loader);
}
for(var i =0; i < 100;i++){
loadSomething(aImages[i].url);
}
-
I try to use Bulkloader to preload images to the application.
Now I have to be absolutely sure that all images are in place or application will not even start working. I would prefer to deal with missing images in the code, and not break whole application.
Is there a way to launch COMPLETE event if not all assets are loaded? I cannot find it.
-
Found it.
BulkLoader.as in _onItemError() calls only function _removeFromConnections(item).
I added _removeFromItems(item), now COMPLETE event is discharged when all existing images are loaded.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|