9 Replies Latest reply on Jun 11, 2009 8:32 AM by kglad

    AS in frame 1 of a linked swf executes, sometimes…

    Applied CD

      I’m using the loader class to load an external swf and attach it to an empty movie clip, the final step follows:

       

      //--------------------------------------------------
      function loadComplete(e:Event):void {
           mc_launch.addChild(gLoader);
           MovieClip(gLoader.content).gotoAndPlay("start");
      }

       

      When navigating away from the movie clip, it’s dumped as follows:

       

      MovieClip(gLoader.content).closeAllStreams();
      gLoader.unload();

       

      The linked swf has two important frames in the beginning. The first frame is labeled “hold” and has the following:

       

      var gSC:SoundChannel = new SoundChannel();
      var gSCBusy:Boolean = false;
      var gSlideIndex:Number = 0;
      var gAudioPosition:Number = 0;
      var gPlayList:Array = ["start","slide01","slide02"]
      var gAudioList:Array = ["intro.mp3","",""]
      var gRunMode:String = Capabilities.playerType;
      stop();

       

      The fifth frame is labled “start” and the singing and dancing begins from there.

       

      The stop(); function in the first frame is used to prevent the loading swf from executing before its 100% downloaded (I had some early trouble where the music would start before the screen assets were in place).

       

      My problem: This works perfectly the first time the linked swf is downloaded and attached, however, if you navigate away and then back I get the error "gSlideIndex NAN" which indicates to me that the first frame in the linked swf is not executed on subsequent attachments, the playhead jumps straight to “start” and my globals are  never declared. Why would a linked swf execute frame 1 the first time it’s attached to mc_launch but not the second?

        • 1. Re: AS in frame 1 of a linked swf executes, sometimes…
          kglad Adobe Community Professional & MVP

          by "linked" swf do you mean "loaded" swf?

           

          by navigate way and then back, do you mean you create another gLoader() and reload your external swf?

           

          do you ever null the previous loader?   does closeAllStreams work?  is there any code in the external swf that changes gSlideIndex?

          1 person found this helpful
          • 2. Re: AS in frame 1 of a linked swf executes, sometimes…
            Applied CD Level 1

            By linked I mean the loaded swf. By navigating away, I mean the main timeline jumps to a frame without mc_launch, the movieclip to which the loader content has been attached, the dump code above is executed, and at a later time the user jumps back back, once again triggering the load and attach functions. Since this data is presumably cached, the second play is very quick. I don’t null the loader but I do execute gLoader.close();

             

            Yes, closeAllStreams(); works although for now all it does is kill the audio stream in the loaded content so it doesn’t continue to play when dumped. gSlideIndex is declared within the loaded swf and is exclusive to it (ie: the external swf declares and manipulates gSlideIndex, the main timeline never references it).

            • 3. Re: AS in frame 1 of a linked swf executes, sometimes…
              kglad Adobe Community Professional & MVP

              what's the external swf do to manipulate gslideindex?  that's where the problem is going to occur.

              • 4. Re: AS in frame 1 of a linked swf executes, sometimes…
                Applied CD Level 1

                gSlideIndex should increment on soundComplete but frankly, it was a last minute code addition to pave the way to incorporate fast forward and rewind buttons gAudioList[gSlideIndex] is the currently playing audio clip, gPlayList[gSlideIndex] is the start frame for that audio, gSlideIndex++ is used to jump forward, gSlideIndex-- to jump back. I thought I put a trace(“Hello”); on frame one to prove it wasn’t executing but it’s late and I’m not sure. I’ll probably have to put this question on hold and do some proper debugging tomorrow.

                • 5. Re: AS in frame 1 of a linked swf executes, sometimes…
                  kglad Adobe Community Professional & MVP

                  try placing a:

                   

                  trace(this+" "+gSlideIndex)

                   

                  in frame 1 of your loaded swf (after gSlideIndex is initialized)

                   

                  do you see what you exect on reload?

                  • 6. Re: AS in frame 1 of a linked swf executes, sometimes…
                    Applied CD Level 1

                    Update: Still not working, but some interesting behavior. I put the following two traces into frame 1 of the loaded swf:

                     

                    trace("check point 1 " +this+" "+gSlideIndex);
                    var gSC:SoundChannel = new SoundChannel();
                    var gSCBusy:Boolean = false;
                    var gSlideIndex:Number = 0;
                    var gAudioPosition:Number = 0;
                    var gPlayList:Array = ["start","slide01","slide02"]
                    var gAudioList:Array = ["U2.mp3","",""]
                    var gRunMode:String = Capabilities.playerType;

                    trace("check point 2 " +this+" "+gSlideIndex);
                    stop();

                     

                    On first play:
                    Check point 1 [movieclip object] NAN
                    Check point 2 [movieclip object] 0

                     

                    On second play:
                    Nothing, the traces are skipped and gSlideIndex throws a NAN error when used in frame 10. I think it’s fairly clear frame 1 is not executing scripts on second play.

                     

                    I have my doubts about this construct in the main timeline:


                    mc_launch.addChild(gLoader);
                    MovieClip(gLoader.content).gotoAndPlay("start");


                    What guarantee do I have that the loaded content has had time to execute frame 1 scripts before the next line in the main timeline bumps the play head to the start frame (frame 10)? … apparently none.

                     

                    So here’s my noobish attempt at a work around. I divided the beginning of the loaded swf into three stages with frame labels mcInit, mcReady, and mcStart. mcInit initializes my globals and some other house keeping with NO stop(); … mcReady is 5 frames later with nothing but a stop(); mcStart is where the real media begins.

                     

                    The main timeline attachement now looks like this:


                    var gMCReadyHold:Timer = new Timer(500,0);
                    mc_launch.addChild(gLoader);
                    MovieClip(gLoader.content).gotoAndPlay("mcInit");
                    gMCReadyHold.addEventListener(TimerEvent.TIMER,onStartMC);
                    gMCReadyHold.start();

                     

                    //----------------------------------------------
                    function onStartMC(event:TimerEvent):void {
                         var myFrame:String = MovieClip(gLoader.content).currentLabel;

                         trace(myFrame);
                         if (myFrame == "mcReady") {
                              gMCReadyHold.removeEventListener(TimerEvent.TIMER,onStartMC);
                              MovieClip(gLoader.content).gotoAndPlay("mcStart");
                         };
                    }

                     

                    The idea is, have the main timeline explicitly force the loaded content to play frame 1 (mcInit), then check at 1/2 second intervals until the loaded content reports it’s reached the mcReady frame. Once the mcReady frame is reached, remove the timer and bump the play head in the loaded content to mcStart.

                     

                    Problem 1: MovieClip(gLoader.content).gotoAndPlay("mcInit"); always throws a frame not found error (I’ve quadruple checked for silly spelling errors). OK, so maybe the loaded content hasn’t had time to establish the frame labels, I comment out that line and it plays fine the first time but on second play:

                     

                    Problem 2: On second play the traces show the loaded content has reached mcReady but the traces on frame 1 are still not executing on second pass. This has got me really puzzled, I would think loading, attaching, and playing external an swf would be fairly routine and shouldn’t be this hard to control.

                     

                    BTW: thanks for reading all of this.

                    • 7. Re: AS in frame 1 of a linked swf executes, sometimes…
                      kglad Adobe Community Professional & MVP

                      put a trace() statement in the "start" frame of your external swf and retest.

                      • 8. Re: AS in frame 1 of a linked swf executes, sometimes…
                        Applied CD Level 1

                        Woot … fixed it. You were on the right track when you asked early on if I was nulling the loader. I was unloading it but never really nulled it. To make this work all I needed was the following when dumping the loaded content:

                         

                        MovieClip(gLoader.content).closeAllStreams();
                        gLoader.unload();
                        gLoader = new Loader();

                         

                        This works on repeated re-loads even with my simpler attachment construct so I’ve abandoned the complicated timer arrangement and gone back to:

                         

                        mc_launch.addChild(gLoader);
                        MovieClip(gLoader.content).gotoAndPlay("mcStart");

                         

                        I found an article that implies this may only be a player 9 issue, but I didn’t read it closely enough to be sure:
                        http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html

                         

                        Thanks for sticking with me on this.