6 Replies Latest reply on Mar 17, 2009 8:45 AM by combustion007

    Loading in a SWF file ... HELP

    combustion007 Level 1
      Hello Everyone,

      I have been trying to load an external SWF file via AS3. I would highly appreciate it if you guys can help me out on this. Please see my code, I have tried all the possible ways that I could think of.

      Thanks a bunch.

      [code]

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">

      <mx:Script>
      <![CDATA[
      import mx.controls.SWFLoader;
      import mx.controls.Alert;
      import flash.utils.*;
      import flash.events.*;
      import flash.net.*;
      import flash.display.*;

      //var ldr:Loader = new Loader();


      function init():void
      {
      var ldr:SWFLoader = new SWFLoader();
      //ldr.source = 'assets/clip1.swf';
      //ldr.source ('assets/clip1.swf');
      //ldr.source = 'assets/clip1.swf';
      //ldr.load('assets/clip1.swf');
      //var req:URLRequest = new URLRequest('assets/clip1.swf');
      this.myCanvas.addChild(ldr);
      }

      ]]>
      </mx:Script>
      <mx:Canvas x="10" y="10" width="1030" height="468" id="myCanvas" backgroundColor="#D55454">
      </mx:Canvas>


      </mx:WindowedApplication>


      [/code]
        • 1. Re: Loading in a SWF file ... HELP
          Sanctor
          Many ways lo load external swf. For example:

          1st way:
          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication creationComplete="init()" layout="absolute" xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Script>
          <![CDATA[
          import mx.controls.SWFLoader;

          private function init():void {
          var ldr:SWFLoader = new SWFLoader();
          this.myCanvas.addChild(ldr);
          ldr.load("clip1.swf");
          }
          ]]>
          </mx:Script>
          <mx:Canvas backgroundColor="#D55454" height="468" id="myCanvas" width="1030" x="10" y="10"/>
          </mx:WindowedApplication>

          2nd way:
          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication creationComplete="init()" layout="absolute" xmlns:mx=" http://www.adobe.com/2006/mxml">

          <mx:Script>
          <![CDATA[
          private function init():void {
          ldr.load("clip1.swf");
          //you can also use this code:
          //ldr.autoLoad = true;
          //ldr.source = "clip1.swf";
          }
          ]]>
          </mx:Script>
          <mx:Canvas backgroundColor="#D55454" height="468" id="myCanvas" width="1030" x="10" y="10">
          <mx:SWFLoader id="ldr" />
          </mx:Canvas>
          </mx:WindowedApplication>

          3rd way:
          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication creationComplete="init()" layout="absolute" xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Canvas backgroundColor="#D55454" height="468" id="myCanvas" width="1030" x="10" y="10">
          <mx:SWFLoader id="ldr" autoLoad="true" source="clip1.swf" />
          </mx:Canvas>
          </mx:WindowedApplication>
          • 2. Re: Loading in a SWF file ... HELP
            combustion007 Level 1
            Thank you so much for your help. I have been at this issue for weeks now and don't know how to resolve it. I have two swf files yet one SWFLOADER. So when user clicks for the "clip1.swf" it gets loaded, and if the user clips for "clip2.swf", the second swf file is loaded within the same SWFLOADER.

            The issue that has become the death of me is to first unload the loaded SWF before loading the next one. I have tried everything that I could find on GOOGLE but when I try to load the next swf, it does get loaded within the same SWFLOADER but then Application crashes. I have been at this for the past 5 weeks and have not made any progress.

            Appreciate if if you can share your thought on this, please.

            Thank you.
            • 3. Re: Loading in a SWF file ... HELP
              Sanctor Level 1
              Why you need to unload first clip?
              Try just set ldr.load("clip2.swf");
              • 4. Re: Loading in a SWF file ... HELP
                combustion007 Level 1
                Hello Sanctor,

                This is what is going on, If I don't unload it, I am still able to hear the first one being played in the back.

                Thanks.
                • 5. Re: Loading in a SWF file ... HELP
                  Sanctor Level 1
                  Before loading second clip SWFLoader must unload the first one.
                  Just try.
                  • 6. Re: Loading in a SWF file ... HELP
                    combustion007 Level 1
                    Sanctor,

                    I have tried in hundreds of times, that is the biggest issue "UNLOADING".
                    SOURCE is the SWFLoader property that could be set to either "null" or "".
                    UNLOAD doesn't work. You can try my code if you like.

                    Thanks.