Your browser does not support iframes.
The above example loads several .swf files into another swf file using BulkLoader’s LazyXMLLoader. You can download the example files here.
This example uses the BulkLoader LazyXMLLoader class, which is convenient as most of the time, you load multiple photos or swf files or videos from an XML file. Press the start button to see it in action.
The Basic Code
// import the bulkloader classes
import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.lazyloaders.*;
import br.com.stimuli.loading.loadingtypes.*;
public class Main extends MovieClip {
public var _bulkLoader:LazyXMLLoader;
public function Main():void {
_bulkLoader = new LazyXMLLoader("SWFs.xml", "loadSomeMovies",1);
_bulkLoader.addEventListener(LazyBulkLoader.LAZY_COMPLETE,
onLazyComplete);
_bulkLoader.addEventListener("complete", completeHandler);
_bulkLoader.addEventListener("progress", progressHandler);}
LazyBulkLoader.LAZY_COMPLETE is a special event that lets you know that the XML file has been downloaded and parsed. You can then attach event listeners for each individual load:
public function onLazyComplete(evt : Event):void {
for each (var item:LoadingItem in _bulkLoader.items) {
item.addEventListener("complete", onMovieLoaded);
item.addEventListener("progress", onMovieProgress); }
}
Using currentTarget to retrieve the ID for BulkLoader
In my example, when an individual item (in this case, a swf file) loads, it calls the onMovieLoaded event, and the currentTarget of that event has an ID which is the same as the ID BulkLoader uses for that item.
private function onMovieLoaded(e:Event) {
var itemSWF:MovieClip =
_bulkLoader.getMovieClip(e.currentTarget.id);
Unique IDs are really key to using BulkLoader – it allows you to control which element is being loaded (if, say, you want to pause other elements and force an item to load first) and also you need it to tell BulkLoader what to do with the item being loaded.
How to prepare your XML file for use with LazyXMLLoader
When you use the LazyXMLLoader class, you use special kind of xml file. See the example or check out the BulkLoader site. When you use this xml file, there is a tag that allows the LazyXMLLoader class to generate a unique id from each file name:
Telling LazyXMLLoader to create auto-ids
<allowsAutoIDFromFileName>true</allowsAutoIDFromFileName>
So, for my file, the filename was Movie_1.swf…which makes LazyXMLLoader create an id, “Movie_1″ (file extensions, such as .swf, and .jpg are removed). So, when the event fires…the currentTarget.id of the event is, “Movie_1″.
You can then use the loadNow() function to call an individual item (and pause everything else from loading):
_bulkLoader.loadNow(put-your-id-here); trace(put-your-id-here); // trace the id to make sure it's correct
So when you trace that item, it should be “Movie_1″.
Another example, when loading SWF files, treat it as a MovieClip:
var itemSWF:MovieClip = _bulkLoader.getMovieClip(e.currentTarget.id);
Setting up the FLA file
There are a few things I do in my example:
1. Uncheck “Automatically Declare Stage Instances”:

This is something I like to do, mostly because I still use instances on the stage. But I also like to extend my symbols with their own classes (for example, if I want to reuse a “Button” movieclip over and over, I would write a class for it so I don’t have to write eventlisteners for MOUSE_OVER and MOUSE_OUT over and over). Extending symbols with instances on your stage causes headaches if you don’t uncheck this checkbox.
The only thing is, once you uncheck this box, you have to remember to declare all your instances on the stage as PUBLIC in your Document Class:
public var myInstance:MyLinkedMovieClip = new MyLinkedMovieClip
or
public var myInstance:MyLinkedMovieClip
Just remember that for “instances” on the stage, you have to use public or you will get a nasty error message.
2. MovieClip Linkages:
Right-click on your symbol in the Library and go to Properties. In the example, I named my MovieClip “GoWhere” (for whatever reason…I think because I’m telling my clip to “Go Where” I want it to…hmmm not very semantic) – so, in my Document Class I wrote:
public var go_1:GoWhere = new GoWhere();
And on the stage in my FLA I gave it an instance name of “go_1″:


