4 Replies Latest reply: May 10, 2013 5:35 AM by dewwondm RSS

    Loading two swfs and playing them sequentially

    dewwondm Community Member

      Hello Team,

       

                 I have searched, but can't seem to find an answer to my question.  I'm working in Flash cs6 on Windows platform. I do not understand how to load two external swf files into another swf file(Main swf) and have them play sequentially. I certain that this task is extremely small to a lot of members of this forum, but if someone could be so kind to assist me with this inquiry I will be over-joyed.

      I am able to load one swf with the following code:

       

      var swf:MovieClip;

      var loader:Loader = new Loader();

       

      var defaultSWF:URLRequest = new URLRequest("swf/gallery.swf");

      loader.load(defaultSWF);

      addChild(loader);

        • 1. Re: Loading two swfs and playing them sequentially
          Ned Murphy CommunityMVP

          One way would be to use the same Loader for both swf's, making the first one's completion trigger the loading of the second.

           

          Another would be to use two different Loaders and have the second one remain invisible until it is called upon to display its content.

           

          In any case, you need to have some way of determining when the first swf is finished playing.  You could have the first dispatch an event and have the main file assign a listener for this event when the first is first loaded.  THat way, when the event is dispatched, the main file can do whatever it needs to do to remove the first and display the second.

          • 2. Re: Loading two swfs and playing them sequentially
            dewwondm Community Member

            Hi Ned, thank you so much for replying.  Not to trouble sir, but is there anyway you could write an example script so that I can get a visual of what the proper script should look like? Thanks.

            • 3. Re: Loading two swfs and playing them sequentially
              Ned Murphy CommunityMVP

              AS3 - Dispatch Event
              --------------------

              Example:

              Add something to trigger the event in the child:


              dispatchEvent(new Event("eventTriggered"));

              (if dispatchEvent problem, see: http://www.kirupa.com/forum/showthread.php?p=1899603#post1899603)


              The listener for this event has to be added to the main file AFTER the external file has been loaded.  In your loading/parent swf, listen for the complete event on the Loader.contentLoaderInfo. 

               

              yourLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);

               

               

              In the complete event handler, add a listener for the event on the loaded swf.


              // event handler triggered when external swf is loaded
              function loaderCompleteHandler(event:Event) {
                  MovieClip(event.currentTarget.content).addEventListener("eventTriggered", eventHandler);
              }

               

              Then just create the event handler for the dispatched event listener that was created in the loaderCompleteHandler function.

               

               

              function eventHandler(event:Event):void {
                  trace("event dispatched in loaded swf");

                  // load/play your second swf now
              }

              • 4. Re: Loading two swfs and playing them sequentially
                dewwondm Community Member

                Ned, good sir, I can't tell how thankful I am for your assistance. This is exactly what I have been looking for, and trying to do for the longest.  YOU ARE THE MAN!!!!