Posted By

elliotrock on 12/17/09


Tagged

image loader as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

netzwerktourist


ImageLoader


 / Published in: ActionScript 3
 

intialize it like:

var newLoader: ImageLoader(); newLoader.load( image_url.jpg ) ; if (newLoader.progress == 100 ) { addChild ( newLoader.newLoader.content as Bitmap ); }

Its in a very basic form, best to dispatch an event from the loaded method back to where you initlize it.

  1. package
  2. {
  3. import flash.display.Loader;
  4. import flash.display.Sprite;
  5. import flash.events.Event;
  6. import flash.events.IEventDispatcher;
  7. import flash.events.ProgressEvent;
  8. import flash.net.URLRequest;
  9.  
  10. public class ImageLoader extends Sprite implements IEventDispatcher
  11. {
  12. public var newLoader : Loader;
  13. private var newRequest : URLRequest;
  14. private var assetsFolder : String;
  15. public var allowDomainUrl : String;
  16. private var percent: Number = 0;
  17.  
  18. public function ImageLoader()
  19. {
  20.  
  21. }
  22. public function load ( thisURL: String ):void{
  23. //
  24. //Security.allowDomain( allowDomainUrl );
  25. this.newLoader = new Loader();
  26.  
  27. //Security.allowDomain("*");
  28. this.newRequest = new URLRequest( thisURL );
  29.  
  30. this.newLoader.load(this.newRequest);
  31. /*
  32. "Grasshopper - Remember to refer to the obj contentLoaderInfo which holds the data as it loads"
  33. */
  34. this.newLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
  35. this.newLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, checkProgress);
  36.  
  37. }
  38.  
  39. public function checkProgress(e:ProgressEvent):void{
  40. //
  41. percent = Math.ceil( e.bytesLoaded / e.bytesTotal ) * 100;
  42.  
  43. }
  44. public function get progress ( ) : Number {
  45. return percent;
  46. }
  47. public function loaded(e:Event): void {
  48. //addChild( this.newLoader.content );
  49. }
  50. }
  51. }

Report this snippet  

You need to login to post a comment.