6 Replies Latest reply: Jul 26, 2012 2:06 AM by cablish RSS

    swfloader load avm1 swf is not work!

    cablish

      my project is flex 4.5,

      swfloader load a SWF file written in ActionScript 1.0 or 2.0,

      it contains ''caurina.transitions.Tweener.addTween".

      But to have a correct work!

      1. run function test1 swf1 is  correct work!

      2. run function test2 swf2 is  correct work!

      code:

      <fx:Script> 
                  [Bindable]
                  private var _byteData:ByteArray;
      
                  public function init() {
                      fileRef = new FileReference();
                      fileRef.addEventListener(Event.SELECT, fileSelected, false, 0, true);
                  }
      
                  private function fileSelected(event:Event):void {
                      fileRef.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
                      fileRef.addEventListener(Event.COMPLETE, fileLoadCompleteHandler);
                      fileRef.load();
                  }
      
                  private function selectHandler(event:Event):void {
                      var filter:FileFilter = new FileFilter("*.swf", "*.swf");
                      fileRef.browse([filter]);
                      fileRef.addEventListener(Event.CANCEL, cancelHandler);
                  }
      
                  private function fileLoadCompleteHandler(event:Event):void {          
                      var loader:Loader = new Loader();
                      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteFunction);
                      loader.loadBytes( event.target.data);
                  }
      
                  private function loaderCompleteFunction(event:Event):void {
                      var loader:Loader = event.target.loader;
                      _byteData = loader.contentLoaderInfo.bytes;
                  }
      
                  // swf1 correct work
                 private function test1():void {
                      swf1.load();
                      swf2.load();
                  }
      
                  // swf2 correct work
                  private function test2():void {
                      swf2.load();
                      swf1.load();
                  }
      </fx:Script>
      <mx:Panel title="SWFLoader Control Example"
                    height="90%"
                    width="90%"
                    paddingTop="10"
                    paddingBottom="10"
                    paddingLeft="10"
                    paddingRight="10">
                <mx:SWFLoader id="swf1" source="{_byteData}"
                            height="100%"
                            width="100%"/>
      
                <mx:SWFLoader id="swf2" source="{_byteData}"
                            height="100%"
                            width="100%"/>
      
               <mx:Button label="test1" click="test1()"/>
              <mx:Button label="test2" click="test2()"/>
          </mx:Panel>
      </s:Application>
      
      
        • 1. Re: swfloader load avm1 swf is not work!
          Flex harUI Adobe Employee

          What error did you get?

          • 3. Re: swfloader load avm1 swf is not work!
            Flex harUI Adobe Employee

            You have two SWFLoaders sharing a single _byteData variable.  That looks suspicious to me.

            • 4. Re: swfloader load avm1 swf is not work!
              cablish Community Member

              Thasks for help!

              i think this problem is  about load as2 swf into as3 applicatin.

              about  _byteData, i tried SWFLoader have self data. and swf file copy two the same file to SWFLoader, the result is the same!

              • 5. Re: swfloader load avm1 swf is not work!
                Flex harUI Adobe Employee

                Maybe I don’t understand the issue.  Each SWF loads correctly by itself?  But when you try to load both only the first one works?

                • 6. Re: swfloader load avm1 swf is not work!
                  cablish Community Member

                  Influence of the rest of you. I'm sorry!

                   

                  issue:

                  swf  file(sound_position_as2_flash8.zip) loaded is only one can run! i want both correctly work!

                   

                  I searched and found this:

                  SWF files written in ActionScript 1.0 or 2.0 cannot load SWF files written in ActionScript 3.0.

                   

                  modify code :

                  <fx:Script>
                              [Bindable]
                              private var _byteData:ByteArray;

                              public function init() {
                                  fileRef = new FileReference();
                                  fileRef.addEventListener(Event.SELECT, fileSelected, false, 0, true);
                              }

                              private function fileSelected(event:Event):void {
                                  fileRef.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
                                  fileRef.addEventListener(Event.COMPLETE, fileLoadCompleteHandler);
                                  fileRef.load();
                              }

                              private function selectHandler(event:Event):void {
                                  var filter:FileFilter = new FileFilter("*.swf", "*.swf");
                                  fileRef.browse([filter]);
                                  fileRef.addEventListener(Event.CANCEL, cancelHandler);
                              }

                              private function fileLoadCompleteHandler(event:Event):void {         
                                 
                  _byteData = event.target.data;
                              }
                  </fx:Script>


                  <mx:Panel title="SWFLoader Control Example"
                                height="90%"
                                width="90%"
                                paddingTop="10"
                                paddingBottom="10"
                                paddingLeft="10"
                                paddingRight="10">


                                      <mx:Button click="selectHandler(event)" label="select swf file"/>

                   

                            <mx:SWFLoader id="swf1" source="{_byteData}"
                                        height="100%"
                                        width="100%"/>

                            <mx:SWFLoader id="swf2" source="{_byteData}"
                                        height="100%"
                                        width="100%"/>
                  </mx:Panel>