Posted By

tuffstudio on 08/01/11


Tagged


Versions (?)

Call function from external SWF in AS3


 / Published in: ActionScript 3
 

The code below assume you have a method in your external SWF called testing().

  1. //This creates a new instance of the loader object.
  2. var my_Loader:Loader = new Loader();
  3.  
  4. var my_loadedSwf:MovieClip;
  5.  
  6. //These listeners detect when the file has finished loading, and if the correct file is
  7. //loaded.
  8. my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
  9. my_Loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
  10.  
  11. //The load method then loads the SWF file into the loader object.
  12. my_Loader.load(new URLRequest("mouseover2.swf"));
  13.  
  14. //This assigns the loaded SWF into a variable which allows the testing() function to be called.
  15. function finishLoading(loadEvent:Event) {
  16. my_loadedSwf = loadEvent.currentTarget.content;
  17.  
  18. addChild(my_loadedSwf);
  19.  
  20. my_loadedSwf.testing();
  21. }
  22.  
  23. function errorHandler(errorEvent:Event):void {
  24. trace("file not found");
  25. }

Report this snippet  

You need to login to post a comment.