4 Replies Latest reply on Feb 3, 2007 11:22 PM by kglad

    Trying to get _totalframes of several swf files

    Zenho
      Hello folks,

      I have a list of swf files and I need to know the amount of frames of each one of them. I tried the following:

      1. I created a xml file called "data.xml" (an example with 5 files - lesson1.swf, lesson2.swf, lesson3.swf, lesson4.swf and lesson5.swf):
      <?xml version="1.0" encoding="iso-8859-1" ?>
      <course>
      <lesson id="1"><name>lesson1</name></lesson>
      <lesson id="2"><name>lesson2</name></lesson>
      <lesson id="3"><name>lesson3</name></lesson>
      <lesson id="4"><name>lesson4</name></lesson>
      <lesson id="5"><name>lesson5</name></lesson>
      </course>

      2. I wrote this script on Flash:

      System.useCodepage = true;
      var MyXML:XML = new XML();
      MyXML.ignoreWhite = true;

      MyXML.onLoad = function($sucess){
      if($sucess){
      for($i=0; $i<MyXML.firstChild.childNodes.length; $i++){
      lessonloaded = MyXML.firstChild.childNodes[$i].firstChild.firstChild.nodeValue;
      loadMovieNum (lessonloaded + ".swf", 10); // loads lesson n .swf on _level10
      _level10.stop();
      trace (_level10._totalframes);
      unloadMovieNum (10);
      }
      } else {
      trace($sucess);
      trace("Error!");
      }
      }
      MyXML.load("data.xml");

      The trace (_level10._totalframes) command results in undefined five times. So I tried the onEnterFrame function, believing that after some loops Flash would recognize the amount of frames of the lesson n .swf file loaded on _level10:

      for($i=0; $i<MyXML.firstChild.childNodes.length; $i++){
      lessonloaded = MyXML.firstChild.childNodes[$i].firstChild.firstChild.nodeValue;
      loadMovieNum (lessonloaded + ".swf", 10);
      _level10.stop();
      onEnterFrame = function(){
      if (_level10._totalframes != undefined) {
      trace (_level10._totalframes);
      unloadMovieNum (10);
      delete this.onEnterFrame;
      }
      }

      }

      But, onEnterFrame function is invoked just once, after the loading of lesson 5.swf. So I get the amount of frames of the last file only.

      Now, I'm a little bit lost... I don't know what to do to improve this script, and I'm wondering if there isn't a better way to get the _totalframes of a list of swf files...

      Any suggestions will be very appreciated!

      Thanks in advance,
      Zenho