1 Reply Latest reply on Aug 27, 2009 7:45 AM by Andrew Rosewarn

    how to replacing default image with the loaded image?

    kkc_mca Level 2

      Hi all,

       

      I have a application which load the remote image, to load the remote it is taking some time

       

      I Would like to place a default image once the image is loaded, I want to replace it

       

      Can any one suggest me the best way to do it

       

      thanks in advance

        • 1. Re: how to replacing default image with the loaded image?
          Andrew Rosewarn Level 3

          Hi

           

          My code below shows a default image in the mxmltag, and then this replaced with a remote image.  Obioulsy for your default image you should embed it so its there ready to go, or make it very small so it loads fast.

           

          I hope this helps.

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
              <mx:Script>
                  <![CDATA[
                      import mx.controls.SWFLoader;
                     
                      // Define a swf loader
                      private var swfLoader:SWFLoader;
                     
                      private function loadBigImage():void {
                          swfLoader = new SWFLoader();
                          // Add a listener to listen forwhen the image is loaded, and call handle complete
                          swfLoader.addEventListener(Event.COMPLETE, handleComplete)
                          swfLoader.load('http://www.maniacworld.com/amazing-cars.jpg')
                      }
                     
                      // Use handle complete to put the content from the loaded swf into the img.source
                      private function handleComplete(event:Event):void {
                          img.source = swfLoader.content;
                          swfLoader = null;
                      }
                  ]]>
              </mx:Script>
             
              <mx:Image id="img" x="205" y="28" complete="loadBigImage()" source="http://weblogs.amny.com/entertainment/stage/blog/family-guy.jpg"/>
          </mx:Application>