Loading an External SWF
Loading an external SWF is a breeze….once you get used to it….
Here’s the code:
var urlToLoad:String = “nameOfSwf.swf”;
//path to SWF that i want to load
var swfLoader:Loader = new Loader();
//you have to make a new loader variable to load the SWF
var swfRequest:URLRequest = new URLRequest(urlToLoad);
//you have to make a new URLRequest to put a URL to load from
swfLoader.load(swfRequest);
//using the .load method will actually load the URL into the loader
addChild(swfLoader);
you will NEVER see what you loaded unless you manually add the loader to the stage
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, accessSWF);
//you cannot access the SWF you loaded on the stage unless you do it once the load has completed. Doesn’t matter if you’re loading a 5kb SWF or a 890kb SWF. Don’t try to access things in the SWF until it’s completed loading or you will get an error saying you’re accessing a null object. It’s there but null because it hasn’t finished loading yet.
function accessSWF(e:ProgressEvent):void
{
//now do something because the SWF has fully loaded.
}
Now you can do different things and use loops and variables to load things onto the stage for more flexibility, but these are the basics!
Good Luck!
About this entry
You’re currently reading “Loading an External SWF,” an entry on Gena’s Blurb
- Published:
- August 11, 2008 / 10:52 am
- Category:
- Actionscript 3.0, General, flash cs3
4 Comments
Jump to comment form | comments rss [?] | trackback uri [?]