Call function from external SWF in AS3
This post will show you how to call a function from an external SWF. I have modified code from the load external SWF tutorial. The code below assume you have a method in your external SWF called testing().
//This creates a new instance of the loader object.
var my_Loader:Loader = new Loader();
var my_loadedSwf:MovieClip;
//These listeners detect when the file has finished loading, and if the correct file is
//loaded.
my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
my_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
//The load method then loads the SWF file into the loader object.
my_Loader.load(new URLRequest("mouseover2.swf"));
//This assigns the loaded SWF into a variable which allows the testing() function to be called.
function finishLoading(loadEvent:Event) {
my_loadedSwf = loadEvent.currentTarget.content;
addChild(my_loadedSwf);
my_loadedSwf.testing();
}
function errorHandler(errorEvent:Event):void {
trace("file not found");
}



2 comments:
thank you so much!!!
I was looking for this, thanks!
Post a Comment