Posted By

weavermedia on 12/02/10


Tagged

as3


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

weavermedia
tombarc
prjohnny


AS3 Load external SWF from URL


 / Published in: ActionScript 3
 

  1. import flash.display.*;
  2. import flash.events.*;
  3.  
  4. private function loadAsset(loadURL:String):void
  5. {
  6. var ldr:Loader = new Loader();
  7. ldr.load(new URLRequest(loadURL));
  8. ldr.contentLoaderInfo.addEventListener(Event.INIT, loadStart);
  9. ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
  10. ldr.contentLoaderInfo.addEventListener(ErrorEvent.ERROR, loadError);
  11. ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
  12. ldr.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError);
  13. }
  14.  
  15. private function loadStart(e:Event):void
  16. {
  17. trace("load start");
  18. ldr.contentLoaderInfo.removeEventListener(Event.INIT, loadStart);
  19. }
  20.  
  21. private function loadError(e:Event):void
  22. {
  23. trace("load error");
  24. ldr.contentLoaderInfo.removeEventListener(ErrorEvent.ERROR, loadError);
  25. ldr.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, loadError);
  26. ldr.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError);
  27. }
  28.  
  29. private function loadComplete(e:Event):void
  30. {
  31. trace("load complete");
  32. ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
  33. addChild(event.target.content) as MovieClip;
  34. }

Report this snippet  

You need to login to post a comment.