Posted By

visualadvance on 08/04/09


Tagged

actionscript 3 loader as3 URLRequest


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

muoto
KDR
dang
shea14
forze
elnota77
tspitzr
GregKepler
miguelrivero
Josueriv


AS3: Image Loader


 / Published in: ActionScript 3
 

A simple way to load images into different holders. Not an end-all solution but its the basics.

  1. loadImage("myImage.jpg",holder1);
  2.  
  3.  
  4. function loadImage(clip:String, holder:MovieClip):void
  5. {
  6. removeChildren(holder);
  7.  
  8. var imageLoader:Loader = new Loader();
  9. var imageURL:String = clip
  10. var imageURLReq:URLRequest = new URLRequest(imageURL);
  11.  
  12. holder.addChild(imageLoader);
  13. trace("loading "+imageURL);
  14.  
  15. imageLoader.load(imageURLReq);
  16. imageLoader.contentLoaderInfo.addEventListener(Event.INIT, imageLoaded);
  17. imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageProgress);
  18. }
  19.  
  20. function imageProgress (evt:ProgressEvent):void
  21. {
  22. //trace(Math.round((evt.bytesLoaded / evt.bytesTotal)*100));
  23. }
  24.  
  25. function imageLoaded(evt:Event):void
  26. {
  27. //var targetLoader:Loader = Loader(evt.target.loader);
  28. //trace("complete");
  29. }
  30.  
  31. function removeChildren (container:MovieClip):void
  32. {
  33. while (container.numChildren)
  34. {
  35. container.removeChildAt (0);
  36. }
  37. }

Report this snippet  

You need to login to post a comment.