Monday, 9 August 2010

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 
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;



function errorHandler(errorEvent:Event):void {
trace("file not found");


bruno 5 March 2011 at 13:38  

thank you so much!!!

MichielDeMey 3 July 2011 at 18:18  

I was looking for this, thanks!

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP