2 Replies Latest reply on Apr 30, 2009 6:18 AM by CPedrick

    how to determine total # of frames in externally loaded .swf file

    CPedrick Level 1

      I need to be able to load a couple of external .swf files and have them play sequentially. To do that, I need to know the number of frames in the first .swf file so that I can check _currentframe against _totalframes to determine when it is finished playing so that I can load the second one.

      Most of the tips I see indicate that _totalframes on an external .swf can be determined by loading the .swf into a container clip and then checking using a listener within .onLoadInit. Like this:

      ------------------------------------------------------------------------------------------ ----------------------------

      this.createEmptyMovieClip("tester_mc", 1);
      var mcListener:Object = new Object();

      mcListener.onLoadInit = function(target_mc:MovieClip) {
          target_mc.onEnterFrame = function() {
              if (this._currentframe >= this._totalframes) {
                  trace("total frames = " + this._totalframes);
                  delete this.onEnterFrame;
              } else {
                  trace(target_mc._currentframe+" OF "+target_mc._totalframes);
              }
          }
      }

       

      var test_mc:MovieClipLoader = new MovieClipLoader();
      test_mc.addListener(mcListener);
      test_mc.loadClip("Ad_Group.swf", tester_mc);

      ------------------------------------------------------------------------------------------ -------------------------------------

       

      Unfortunately, that doesn't seem to work. The trace always returns a total frames of 1.

      I imagine this is because the container movie clip only has 1 frame, and the external .swf timeline appears to be ignored.

       

      I'd very much appreciate any thoughts on how to gather the total frames of an external .swf file or, alternatively, tell in some other way when it is finished playing. (Not just loading, but playing to the end.)

       

      TIA,

      C

        • 1. Re: how to determine total # of frames in externally loaded .swf file
          Rothrock Level 5
          I imagine this is because the container movie clip only has 1 frame, and the external .swf timeline appears to be ignored.


          I wouldn't imagine that. My guess is that the main timeline of the external swf does only have 1 frame and that the rest of the animation is inside a movieclip on that timeline. Did you publish this swf? Can you open the FLA and check how many frames are on on the main timeline?

           

          The approach you have outlined is pretty much what there is. But it only knows to check one timeline. If there are many nested movieclips it may be impossible to figure out which timeline you really want to have be "THE" total timeline.

           

          If you have the FLA you can have the clip call a function on the _root timeline that tells the main swf that a movieclip has completed or something like that.

           

          I also have in my head somewhere that I recently saw something that somebody did similar to this, but can't remember...If it pops back into my head I'll post it.

          • 2. Re: how to determine total # of frames in externally loaded .swf file
            CPedrick Level 1

            BINGO!!!!!!!!!!!!!!!!!

            (and THANK YOU THANK YOU THANK YOU!!!)

             

            The only remaining question is... Why didn't I think of that?

             

            The .swf that I was loading only was created by someone else so I was not aware that the entire contents was in a movie clip on the main stage, which then had only one frame in it. I carried all of the stuff in the movie clip up to the root timeline and the code to figure out frames now works beautifully (restoring my faith in my general ability to code, if not my general troubleshooting skills...  

             

            Thank you again for the speedy response. This solved a MAJOR roadblock in an important project for me.

             

            ~C