Trying to get _totalframes of several swf files

Trying to get _totalframes of several swf files

Post 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
 
 
 

Trying to get _totalframes of several swf files

Post by kgla » Fri, 02 Feb 2007 11:13:06

you have to wait until loading starts before you can access anything about the
loading swf, including its _totalframes.

so, your 2nd bit of code is a step in the right direction. but your
repeatedly defining (and over-writing the previous) onEnterFrame handler.

try:



loadA = [];
totalFramesA = [];
MyXML.onLoad = function($sucess){
if($sucess){
for ($i=0; $i<MyXML.firstChild.childNodes.length; $i++) {
lessonloaded =
MyXML.firstChild.childNodes[$i].firstChild.firstChild.nodeValue;
loadA.push(lessonloaded);
}
}
}
lo = new Object();
mcl = new MovieClipLoader();
lo.onLoadStart = function(target) {
totalFrameA[index] = target._totalframes;
index++;
if (index<loadA.length) {
mcl.loadClip(loadA[index]+".swf", 10);
} else {
framesF();
}
};
function framesF() {
// _totalframes stored in totalFrameA. do whatever
}
mcl.addListener(lo);
mcl.loadClip(loadA[0]+".swf", 10);
MyXML.load("data.xml");

 
 
 

Trying to get _totalframes of several swf files

Post by Zenh » Mon, 05 Feb 2007 03:49:47

First, thanks for the help kglad!

It didn't work here, "Error opening URL "..../undefined.swf". I'm not sure if
I understood how the function invoked by onLoadStart fullfills the loadA array
(specially how the "target" parameter is passed).

But I will study the events and methods of MovieClipLoader, it seems more
promising than loadMovieNum. In the meantime, I would like other suggestions!
Thanks!
 
 
 

Trying to get _totalframes of several swf files

Post by Zenh » Mon, 05 Feb 2007 08:35:40

Woo-hoo!! Now I got it! The problem was where loadClip was being called... I
moved it right bellow the for loop, and now it works!



MyXML = new XML();
MyXML.ignoreWhite = true;

loadA = new Array();

MyXML.onLoad = function($success){
if($success){
for ($i=0; $i<MyXML.firstChild.childNodes.length; $i++) {
loadA[$i] = MyXML.firstChild.childNodes[$i].firstChild.firstChild.nodeValue;
}
objMCL.loadClip(loadA[0] + ".swf", lesson_mc);
}
}
MyXML.load("data.xml");

this.createEmptyMovieClip("lesson_mc", 1);
objMCL = new MovieClipLoader();
objL = new Object();
index = 0;
objL.onLoadComplete = function(target:MovieClip):Void{
trace (loadA[index] + " - " + target._totalframes + " frames");
objMCL.unloadClip(lesson_mc);
index++;
if (index<loadA.length){
objMCL.loadClip(loadA[index] + ".swf", lesson_mc);
}
}
objMCL.addListener(objL);
 
 
 

Trying to get _totalframes of several swf files

Post by kgla » Mon, 05 Feb 2007 16:22:39

great! and you're welcome.