Groups | Blog | Home
all groups > flash actionscript > december 2006 >

flash actionscript : displying the duration of loaded .swf files



bb73
12/21/2006 8:14:13 PM
I've created an online Flash presentation that works by loading numerous .swf
files into a container. It can be viewed here:
http://www.aafp.org/multimedia/chittest4/

As each .swf plays, another is automatically loaded. Since the duration runs
about 30 minutes I want to show the viewer how far into the presentation they
are at any given time, simiar to a progress indicator when watching a video.
I've created a progress bar that resides in the container file and it kind of
works, but it's not built correctly. I had to fake it (no need to go into
detail) to make seem like it's monitoring the duation. Is there a way to
create something that shows tells the whole length of the presentation and then
count's down? For instance having a little box that starts off at 30:00
minutes and counts down as the presentation plays until it hits 00:00 and it's
over. I'm just not sure where to start in setting something like this up,
espcially since the entire presentation consists of mulitple .swfs.
thanks!
myIP
12/21/2006 9:26:36 PM
How are these SWFs being played? Are they movies that are played from the
timeline? Are they loading a FLV into them? How is this ?time? being clocked?
Depending on your answer will determine what code will be needed.
bb73
12/21/2006 9:49:31 PM
Yes, they are movies played from the timeline. No .flvs involved. The
container file calls on each .swf file to load into a target on the container's
timline. Each .swf then plays through one at a time and the next .swf in line
gets loaded upon completion. There are keyframes that conaint actionscript
that says to load a specific .swf, then load the next one upon completion. The
following is the code used to load the first .swf (001.swf, then load the next
one in line, with is 004.swf:


/*Indicates name of SWF to play. Used by loaded and preloaded
SWFs to prevent premature playback.*/
SWFPlayIndic = "001.swf";

/*Calls function Preloader and sets
1) External SWF to load for playback
2) External SWF to preload for playback in next frame.*/
Preloader("MM4/001.swf","MM4/004.swf");

stop();


Right now I'm not actually clocking the time. There is are separate movie
clips in the container file that are assigned to each .swf that play the
progress bar as each swf is loaded. Ilke I said before, I had to fake it. :)
Jeckyl
12/22/2006 12:00:00 AM
If all the SWF's are loaded, you can look at the _totalFrames property of
each to calculate the number of frames. AS you know the framerate, you can
easily calculate the times from that (this is assumign the SWF's don't loop
and just play from start to end)
--
Jeckyl

myIP
12/22/2006 2:05:36 PM
Yeah, if you are not using FLVs then do what Jeckyl suggested. The code below
will load a SWF and when the onLoadInit event handler is invoked it will
retrieve the incoming SWF?s totalframes property. I then divided this value by
the FPS (frames-per-second) value (12). I don?t think there is an easy way to
find out the SWF?s FPS. Also this code creates an empty movieclip 'container'
that loads the incoming SWF.

var container:MovieClip = createEmptyMovieClip("container",
getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.addListener(this);
mcLoader.loadClip("MM4/004.swf", container);

function onLoadInit(mc:MovieClip) {
trace("onLoadInit: " + mc);
trace(mc._totalframes/12)
}
Denise Hambrick
2/21/2007 4:32:39 AM
I have a similar requirement to show current time and total time of separate
swfs that each include flvs and some interactions. Is there a way to monitor
the time to complete or elapsed time to total time with this situation?

If I can do this for one, I'm thinking I can have the start time for the
second one begin at the end time of the first one and so on. Each swf
(actually exe) file is on a separate CD.

Any ideas?
Thanks,
Denise
myIP
2/21/2007 3:35:37 PM
Having interactions in a SWF would make it impossible to predict the total time
as you probably know. Having key points in the application which will update
the amount of time that is left would be ideal. You can monitor the user?s
current time by using setInterval( ) and/or getTimer().
Denise Hambrick
2/22/2007 4:19:01 AM
Thanks. I check into that. I may come back with more questions, but this gives me a place to work from.

Thanks,
AddThis Social Bookmark Button