0 Replies Latest reply on Sep 3, 2010 9:53 PM by micguo2000

    Problem with SWFloader when switch source.

    micguo2000

      I have difficult to reload content with SWFloader. It seems it can not convert relative path correctly to absolute path. Here is my code

       


      <fx:Script>
        <![CDATA[
         import mx.controls.Image;
         import mx.controls.SWFLoader;

         private var myimg:Image = new Image;
         public function init():void{
          myimg.x = 100;
          myimg.y = 100;
          myimg.width = 200;
          myimg.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
          myimg.addEventListener(Event.COMPLETE,myimgLoadCompleteHandler);
          myimg.load("./upload/1.jpg")
         }
         private function ioErrorHandler(e:IOErrorEvent):void{
           mx.controls.Alert.show(e.text);
          }
         private function myimgLoadCompleteHandler(e:Event):void{
          var img:Image = e.currentTarget as Image;
          myimg.removeEventListener(Event.COMPLETE,myimgLoadCompleteHandler);
          addElement(img);
         }
         public function imgChangeButtonClickHandler():void{
          removeElement(myimg);
          myimg.unloadAndStop();
          myimg.addEventListener(Event.COMPLETE,myimgLoadCompleteHandler);
          myimg.load("./upload/1.jpg");   
         }

        ]]>
      </fx:Script>
      <s:Button id = "imgChangeButton" click="imgChangeButtonClickHandler()"/>

       

      The html file contains swf is located at http://127.0.0.1:8080/swfloaderTest/. The swf file is located at http://127.0.0.1:8080/swfloaderTest/swf/. The image file is located at http://127.0.0.1:8080/swfloaderTest/upload/

       

      Whenthe swf file loaded, the image is correctly loaded to the stage. But when I try to reloaded it by click imgChangeButton, it would not

      work. Both time, I use the same relative path, WHY the result it different. I know it says in SWFloader.as "// make relative paths relative

      to the SWF loading it, not the top-level SWF". But if I obey this rule, the first load operation would not work.

       

      Is anyone know the reason for this problem? Thanks a lot!!!