by Zenh » Fri, 02 Feb 2007 09:03:02
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[b][i]n[/i][/b].swf on _level10
_level10.stop();
[b]trace (_level10._totalframes);[/b]
unloadMovieNum (10);
}
} else {
trace($sucess);
trace("Error!");
}
}
MyXML.load("data.xml");
The [b]trace (_level10._totalframes)[/b] command results in [b]undefined[/b]
five times. So I tried the onEnterFrame function, believing that after some
loops Flash would recognize the amount of frames of the
lesson[b][i]n[/i][/b].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();
[b]onEnterFrame = function(){
if (_level10._totalframes != undefined) {
trace (_level10._totalframes);
unloadMovieNum (10);
delete this.onEnterFrame;
}
}[/b]
}
But, onEnterFrame function is invoked just once, after the loading of
lesson[b]5[/b].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