1 Reply Latest reply on Jun 17, 2010 5:06 AM by BhaskerChari

    Embeding images when the name is passed in a variable

    post2umesh Level 1

      I have a situation where in I get to know the name of the image to be used at run time in a variable. How can I use this image as a source fot bitmap image component.

        • 1. Re: Embeding images when the name is passed in a variable
          BhaskerChari Level 4

          Hi Umesh,


          You need to use the Loader class and load the image and in Complete event of Loader you can access the data and assign it to the bitmap..


          Check the code below:


          private var loader:Loader;
                   private function onImageLoadComplete(event:Event):void
              imgData = loader.content as ByteArray;
              var bitmapData:BitmapData = Bitmap(loader.content).bitmapData;
              var bitmapImage:Bitmap;
              bitmapImage.source = new Bitmap(bitmapData);   
              trace("\rStatus: image loaded ");
                   public function loadImage():void
                    loader = new Loader();
                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoadComplete);
              loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
              loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
              loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
                       loader.load(new URLRequest("images/dimpause.gif"));
                    private function securityErrorHandler(event:SecurityErrorEvent):void
                       trace("securityErrorHandler: " + event);
                 private function httpStatusHandler(event:HTTPStatusEvent):void
                       trace("httpStatusHandler: " + event);           
                    private function ioErrorHandler(event:IOErrorEvent):void
                       trace("ioErrorHandler: " + event);



          If this post answers your question or helps, please kindly mark it as such.


          Bhasker Chari