call a function from external swf


/ Published in: ActionScript 3
Save to your folder(s)

code below assumes you have method testing() in external swf.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.