BulkLoader class usage

Source: Internet
Author: User

BulkLoader provides a simple loading function. It uses only the same interface whether it is xml, swf, or sound files to be loaded. It is highly recommended to have powerful functions.

 

Usage: load the xml file:

Var bulkLoader: BulkLoader = new BulkLoader ('main loading ');
BulkLoader. add ('My _ xml_file.xml ');
BulkLoader. start ();

Reference the previously loaded Resource:

Var myXML: XML = BulkLoader. getLoader ("main loading"). getXML ("my_xml_file.xml ");

 

More comprehensive usage:

 

Package {
Import br.com. stimuli. loading. BulkLoader;
Import br.com. stimuli. loading. BulkProgressEvent;
Import flash. events .*;
Import flash. display .*;
Import flash. media .*;
Import flash.net .*;

Public class SimpleExampleMain extends MovieClip {
Public var loader: BulkLoader;
Public var v: Video;
Public var counter: int = 0;

Public function SimpleExampleMain (){
// You need to give the BulkLoader a name when constructing it.
Loader = new BulkLoader ("main-site ");
// Set the output log
Loader. logLevel = BulkLoader. LOG_INFO;
// After the build, add the object to be loaded to the queue through the add method.
Loader. add ("photo.png ");
// When adding an object to be loaded, you can also add an id for it to facilitate future calls.
Loader. add ("images.jpg", {id: "bg "});
// You can also adjust the loading sequence of the loaded object through the priority attribute. The larger the priority value, the higher the priority, and the earlier the loading.
Loader. add ("list. xml", {priority: 20, id: "config-xml "});
// Load an animation. You can use the pausedAtStart attribute to pause the animation when loading the animation.
Loader. add ("mov. fla", {maxTries: 6, id: "the-video", pausedAtStart: true });
// The maxTries attribute is used to set the number of retries when loading fails. Note that the "id" here uses the string name.
Loader. add ("song.mp3", {"id": "soundtrack", maxTries: 1, priority: 100 });

// Reading the latest version of the document, swf and json are supported.

// Add a COMPLETE event, which is triggered after all objects in the queue are loaded.
Loader. addEventListener (BulkLoader. COMPLETE, onAllItemsLoaded );

// Add a PROGRESS event, which will be continuously triggered when the queue is loaded. It is usually used to listen on the loading progress.
Loader. addEventListener (BulkLoader. PROGRESS, onAllItemsProgress );

// After the queue is edited, use the star method to start loading the queue.
Loader. start ();
}
Public function onAllItemsLoaded (evt: Event): void {
Trace ("every thing is loaded! ");
// Create a Video object
Var video: Video = new Video ();
// Extract the video stream just loaded from the queue
Var theNetStream: NetStream = loader. getNetStream ("the-video ");
AddChild (video );
Video. attachNetStream (theNetStream );
TheNetStream. resume ();
Video. y = 300;
// Extract the image

// You can extract objects directly through URLs.
Var bitmapCats: Bitmap = loader. getBitmap ("photo.png ");
BitmapCats. width = 200;
BitmapCats. scaleY = bitmapCats. scaleX;
AddChild (bitmapCats );

// Of course, you can also extract objects by id
Var bitmapShoes: Bitmap = loader. getBitmap ("bg ");
BitmapShoes. width = 200;
BitmapShoes. scaleY = bitmapShoes. scaleX;
BitmapShoes. x = 220;
AddChild (bitmapShoes );

// Extract audio
Var soundtrack: Sound = loader. getSound ("soundtrack ");
Soundtrack. play ();

// Extract an xml document
Var theXML: XML = loader. getXML ("config-xml ");
Trace (theXML );
}
// You can use the loadingStatus method of BulkProgressEvent to display all information during the loading process!
Public function onAllItemsProgress (evt: BulkProgressEvent): void {
Trace (evt. loadingStatus ());
}
}
}

Specifically, this is to add a progess event. when too many objects are loaded, the totalBytes in the function cannot synchronously obtain the Bytes and evt of all resources. the loadingStatus () method lists all the attributes that onProgess can detect. Through N, I am sure this is a BUG. LoadedBytes is normally displayed, and totalBytes will be available only when loading is nearing completion. I checked the code. google's document found a method and has not verified loader. get ("id "). addEventListener (Event. COMPLETE, onBackgroundLoaded) to obtain specific support from many resources and apply it to the Complete method. Can the application be applied to PROGRESS? If you execute break after obtaining a single resource and then add the totalBytes of a single resource, can you get the totalBytes that we cannot get in the onProgess method?

 

Article transferred from: http://amazonite.blog.sohu.com/131966709.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.