Loading Images : URLLoader « Network « Flash / Flex / ActionScript






Loading Images

 
package {

    import flash.display.Sprite;
    import flash.utils.ByteArray;
    import flash.display.Loader;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import flash.geom.Rectangle;
    import flash.events.Event;

    public class Main extends Sprite {

        private var urlLoader:URLLoader = new URLLoader();

        public function Main() {
            urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
            urlLoader.load(new URLRequest("http://www.java2s.com/image2.jpg"));

           urlLoader.addEventListener(Event.COMPLETE, completeHandler);
       }

       private function completeHandler(event:Event):void {
           var loader:Loader = new Loader();
           loader.loadBytes(urlLoader.data);
           addChild(loader);
       }
    }
}

        








Related examples in the same category

1.Loading XML
2.Add IOErrorEvent, HTTPStatusEvent, SecurityErrorEvent and Event.COMPLETE to URLLoader
3.Trace loader data
4.Listen to the URLLoader complete event
5.Loading a Block of Text (Including HTML and XML)
6.Checking Load Progress
7.Understanding Flash Player Security
8.Load a picture
9.Display LoadBar
10.Load an XML file
11.Events and Event Handling for URLLoader
12.Event Listener Registration Examples
13.Accessing the Target Object
14.URLLoader Complete event
15.Accessing the Object That Registered the Listener