AS3: Image load


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



Copy this code and paste it in your HTML
  1. import flash.events.*;
  2. import flash.display.Loader;
  3. import flash.display.LoaderInfo;
  4. import flash.net.URLLoader;
  5. import flash.net.URLRequest;
  6.  
  7. var url:String = "http://domain.com/image.png";
  8. var myLoader:Loader;
  9. myLoader= new Loader();
  10. myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
  11. myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
  12. myLoader.load(new URLRequest(url));
  13.  
  14. function onProgress(e:ProgressEvent):void
  15. {
  16. var p:Number = (e.bytesLoaded / e.bytesTotal);
  17. }
  18. function onComplete(e:Event):void
  19. {
  20. myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
  21. //e.target.content.bitmapData
  22. stage.addChild(myLoader);
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.