SHARE
TWEET

Untitled

a guest Jun 19th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var loader:Loader =new Loader();
  2.  
  3. this.addChild(loader);
  4.  
  5. loader.x=65;
  6.  
  7. loader.y=50;
  8.  
  9.  
  10.  
  11. //Note: listeners are added to the contentLoaderInfo property of 'loader'
  12.  
  13. //and not to 'loader' itself.
  14.  
  15.  
  16.  
  17. loader.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoad);
  18.  
  19.  
  20.  
  21. //If you don't expect loading errors and do not care to display
  22.  
  23. //loading progress, you don't need the next two listeners.
  24.  
  25.  
  26.  
  27. loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadingError);
  28.  
  29. loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,updateInfo);
  30.  
  31.  
  32.  
  33. btnLoad.addEventListener(MouseEvent.CLICK,doLoad);
  34.  
  35. infoBox.text="Click the arrow button to load an image.";
  36.  
  37.  
  38.  
  39. //Since we load only one image, we remove the button's listener and make
  40.  
  41. //the button invisible when loading begins.
  42.  
  43.  
  44.  
  45. function doLoad(e:MouseEvent):void {
  46.  
  47. loader.load(new URLRequest("space2.jpg"));
  48.  
  49. infoBox.text="Loading starts...";
  50.  
  51. btnLoad.removeEventListener(MouseEvent.CLICK,doLoad);
  52.  
  53. btnLoad.visible=false;
  54.  
  55. }
  56.  
  57.  
  58.  
  59. function updateInfo(e:ProgressEvent):void {
  60.  
  61. infoBox.text="Loading: "+String(Math.floor(e.bytesLoaded/1024))+" KB of "+String(Math.floor(e.bytesTotal/1024))+" KB.";
  62.  
  63. }
  64.  
  65.  
  66.  
  67. function loadingError(e:IOErrorEvent):void {
  68.  
  69. infoBox.text="There has been an error loading the image. The server may be busy. Refresh the page and try again.";
  70.  
  71. }
  72.  
  73.  
  74.  
  75. function doneLoad(e:Event):void {
  76.  
  77. loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,doneLoad);
  78.  
  79. loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,updateInfo);
  80.  
  81. loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,loadingError);
  82.  
  83. infoBox.text="";
  84.  
  85. infoBox.visible=false;
  86.  
  87. }
RAW Paste Data
Top