Flash: Dynamically Load Image in ActionScript 3.0

  1. Create image placeholder movie
  2. Add image placeholder movie on stage, name it "image_placeholder"
  3. Click on the first frame of the default layer and add the following:
    var myLoader:Loader = new Loader();
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderReady);
    
    var fileRequest:URLRequest = new URLRequest("photo.jpg");
    myLoader.load(fileRequest);
    
    function onProgressStatus(e:ProgressEvent) {   
          trace(e.bytesLoaded, e.bytesTotal); 
    }
    
    function onLoaderReady(e:Event) {     
          image_placeholder.addChild(myLoader);
    }
    
    stop();

No comments: