Groups | Blog | Home
all groups > flash actionscript > september 2004 >

flash actionscript : Preload swf woes. Googled with no luck on a solution



Joey D
9/19/2004 10:44:30 PM
Am I crazy? This should work right?

I have tried this http://www.bokelberg.de/actionscript/1.html and does not
seem to work.

Essentially I have a movie that will load an external swf. I need to preload
this swf along with the main movie. The main timeline and the external swf
are to be synced together. So when the external swf and the main movie load
fully they will start to play at the same time.

Unfortunately, I can not get this working correctly. Here is what I have.
By the way. The external swf does not have a stop action in it. It is from a
3rd party software program. It does have audio, otherwise I would have
imported it into the main movie. Any help greatly appreciated!

Frame 1
loadMovieNum("myexternal.swf",1);
stop();

Frame 2
(nothing here)

Frame 3
// get the bytes loaded so far or 0 if we didn't start loading yet
actBytes = _level1.getBytesLoaded() || 0;
// get the total bytes to load or 100 if we didn't start loading yet
totBytes = _level1.getBytesTotal() || 100;
// calculate a percentage value of the bytes loaded
percent = Math.round(actBytes * 100 / totBytes);

// if there are more bytes to load
if( totBytes - actBytes > 10){
// if you don't want a bar, delete the following line
bar._xscale = percent;
// go back to the loop
gotoAndPlay(2)
}

--
Joey Durham
www.ultraweaver.com - Tutorials/Downloads

kglad
9/20/2004 5:55:32 AM
if you can't control the external swf you'll need to ensure that your main
movie is loaded and ready when your external swf starts playing, which may be
before the external swf is completely loaded. and this later fact may be
problematic.

in fact, if i were you, i'd decompile that external swf and put a blank
keyframe on frame 1 and add a stop() to it. that would probably be the easiest
and most satisfactory way of handling this. if you want, you can zip and
upload that external file and i can see if i can decompile it for you.
Joey D
9/20/2004 12:06:24 PM
Thanks for the reply!

I was able to get a stop action in the first frame of the external swf. Now
I am having problems just getting it to preload . This is the code I have.
What I need to have happen is the timeline of the main and external swf stop
until the external files has been fully loaded. Once the external swf is
loaded play both the main and external swf.

Proving to be a big thorn in my side. : (

I have tried many methods to get this going. None that provide working
examples of my situation though. Any help on this would be awesome.

Frame 1
loadMovieNum("myexternal.swf",1);

Frame 2
(nothing here)

Frame 3
// get the bytes loaded so far or 0 if we didn't start loading yet
actBytes = _level1.getBytesLoaded() || 0;
// get the total bytes to load or 100 if we didn't start loading yet
totBytes = _level1.getBytesTotal() || 100;
// calculate a percentage value of the bytes loaded
percent = Math.round(actBytes * 100 / totBytes);

// if there are more bytes to load
if( totBytes - actBytes > 10){
// if you don't want a bar, delete the following line
bar._xscale = percent;
// go back to the loop
gotoAndPlay(2)
}



--
Joey Durham
www.ultraweaver.com - Tutorials/Downloads
www.geekforum.com - See Fireworks Section. Unbelievable!
TMM Volunteer - Fireworks


[quoted text, click to view]

Patrick Bay
9/20/2004 3:24:54 PM
Hi,

That's rather strange code you have there:

actBytes = _level1.getBytesLoaded() || 0;

totBytes = _level1.getBytesTotal() || 100;

You're using a logical OR comparator. It will only return TRUE or FALSE
(first of all), and only when getBytesLoaded or getBytesTotal are 1. Any
other time they will return 0 (because 0 is logical FALSE and 100
decimal's lower bit is also logical FALSE). Also, your percentage
calculation is not correct. From what I can tell, this shouldn't work at
all. Get rid of those logical ORs...

Do something like this:

// get the bytes loaded so far or 0 if we didn't start loading yet
actBytes = _level1.getBytesLoaded();
// get the total bytes to load or 100 if we didn't start loading yet
totBytes = _level1.getBytesTotal();
// calculate a percentage value of the bytes loaded
percent = Math.round((actBytes/totBytes)*100);


// if there are more bytes to load
if( percent<100 ){
// if you don't want a bar, delete the following line
bar._xscale = percent;
// go back to the loop
gotoAndPlay(2)
}

Regards,
Patrick

-----------------------------------------------------
www.baynewmedia.com

IRC (www.dal.net) -> #baynewmedia
-----------------------------------------------------



[quoted text, click to view]
Joey D
9/20/2004 3:40:18 PM
Thanks Patrick!

Essentially I have a movie that will load an external swf. I need to preload
this swf along with the main movie. The main timeline and the external swf
are to be synced together. So when the external swf and the main movie load
fully they will start to play at the same time.

The main movie has a timeline that is just as long as the external clip.
They should play at the same time when loading of the external swf is done.
The main movie is not heavy in file size at all. It is the external swf that
is and can be up to a couple of megs.

Does this make since? Again thanks for stepping in with some direction.

--
Joey Durham
www.ultraweaver.com - Tutorials/Downloads


[quoted text, click to view]

kglad
9/21/2004 1:54:59 AM
in frame 1 of your _level0 movie put the following code and whatever preload
stuff you want (like bar):

loadMovieNum("myexternal.swf", 1);
stop();
preloadI = setInterval(preloadF, 100);
function preloadF() {
loaded = _level1.getBytesLoaded()+_level0.getBytesLoaded();
total = _level1.getBytesTotal()+_level0.getBytesLoaded();
if (loaded>=total) {
clearInterval(preloadI);
//do whatever. ur movies r loaded.
} else {
percent = Math.round(loaded*100/total);
bar._xscale = percent;
}
}
AddThis Social Bookmark Button