1 Reply Latest reply on May 17, 2010 5:00 AM by Ned Murphy

    Detect end of swf & reload another

    anecdote1

      Hi,

       

      Currently I am using this code to play a selection of .swf files using the keyboard.

       

      var myrequest:URLRequest=new URLRequest("1.swf");

      var myloader:Loader=new Loader();

      myloader.load(myrequest);

      stage.addChild(myloader);


      //Adds event listener to the stage.

      stage.addEventListener(KeyboardEvent.KEY_DOWN, detectKey);


      function detectKey(event:KeyboardEvent):void {

      if (event.keyCode==81) {

         var myrequest1:URLRequest=new URLRequest("2.swf");

      myloader.load(myrequest1);

      }


      if (event.keyCode==87) {

         var myrequest2:URLRequest=new URLRequest("1.swf");

      myloader.load(myrequest2);

      }


      if (event.keyCode==69) {

        var myrequest3:URLRequest=new URLRequest("3.swf");

      myloader.load(myrequest3);

      }

      }

       

      Now I would like to detect the end of, say, 1.swf to load into a different swf, does anyone know how best to acheive this? I have tried a few tutorials with no success!

       

      Many Thanks

        • 1. Re: Detect end of swf & reload another
          Ned Murphy Adobe Community Professional & MVP

          One way would be to have each swf be assigned an event listener after being loaded so that you could have each one dispatch an event when they complete.  The event handler function for the listener would take care of loading the next swf.

           

          Another approach, if these are frame by frame animations, could be to continually compare the currentFrame versus the totalFrames as soon as the files are loaded and initialized.  When the two values are equal, trigger loading the next.

           

          In both cases you should include listeners to determine when the files are loaded before establishing either method.