...

View Full Version : Preloading Question



aWishResigned
04-17-2008, 11:13 PM
This is something that's bugged me for years and I've just never gotten around to addressing it.

Say I've got a movie with a bitmap (that's has a relatively large filesize) for a background that starts on frame 2 and a preloader (which is entirely vector and therefore not that big of a file) that is on frame 1. Even though the bitmap hasn't loaded yet, the movie still stalls until it has loaded, making the preloader seemingly start at say 60 or 70 percent.

Can anyone here explain to me what's going on and what I could maybe do to fix it?

gnomeontherun
04-17-2008, 11:22 PM
It depends on how your preloader is setup. Does it load by frames or by filesize? Do you have some code to show?

aWishResigned
04-17-2008, 11:30 PM
Sure. It's a simple onEnterFrame that cycles and checks the loaded bytes against the total bytes. Here's the code:


this.onEnterFrame = function() {
if (picture_one_mc._loaded && picture_two_mc._loaded && picture_three_mc._loaded) {
delete this.onEnterFrame;

var pre_out:Tween = new Tween(preload_mc, '_alpha', Regular.easeOut, 100, 0, 5, false);
pre_out.onMotionFinished = function() {
_root.play();
}

} else {
var bl:Number = (picture_one_mc.picture_mc.getBytesLoaded() + picture_two_mc.picture_mc.getBytesLoaded() + picture_three_mc.picture_mc.getBytesLoaded() + _root.getBytesLoaded());
var bt:Number = (picture_one_mc.picture_mc.getBytesTotal() + picture_two_mc.picture_mc.getBytesTotal() + picture_three_mc.picture_mc.getBytesTotal() + _root.getBytesTotal());
preload_mc.bar_mc._width = Math.floor((bl / bt) * 305);
}
}

I'd like to point out that the picture_one_mc._loaded stuff is based on individual images being called to load. They're just booleans that help me to know if I should even worry about the preloader at all.

gnomeontherun
04-18-2008, 01:38 AM
I think your math is more complicated than it needs to be.

Assuming it is on the first frame, root timeline, why not try


else {
var bl:Number = Math.round(this.getBytesLoaded());
var bt:Number = Math.round(this.getBytesTotal());
preload_mc.bar_mc._width = Math.round(bl / bt * 100 * 305);
}

This would just get the size of the movie, and not have to pull the individual elements.

aWishResigned
04-18-2008, 03:03 PM
You're exactly right and, if it were any other project, I would agree wholeheartedly. This particular project involves cues within a movie which mean that they have to be loaded before the movie even starts.

This is just a generic code block to illustrate my point better:


stop();
this.onEnterFrame = function() {
var bl:Number = _root.getBytesLoaded();
var bt:Number = _root.getBytesTotal();

if (bl >= bt) {
delete this.onEnterFrame;
_root.play();
} else {
preload_mc.bar_mc._width = Math.round((bl / bt) * 300);
}
};

gnomeontherun
04-18-2008, 04:36 PM
Ok, cues within the Flash video? The term movie is ambiguous :)

aWishResigned
04-18-2008, 04:41 PM
Yes, cues within a flash video but, what I meant was that the fact that there was a video in the movie is not important. All I'm looking for is to know how flash will load a movie. If, when there is a large filesize in frame 2, why can't I get a preloader to start eariler in frame 1. It will usually just be a white screen and then appear when the preloader is about halfway complete.

gnomeontherun
04-18-2008, 09:34 PM
I take it you've tried the simplified version of the code? Is the file in frame 2 being loaded from an external source or as part of the swf?

Do you have the page url to show? I'm curious to see this, maybe I'll understand better. I'm not sure I can answer this, but I still don't know why you need to add the three movieclip sizes together, and then use the entire filesize. It seems (in my understanding) that you are actually adding up the total twice.

aWishResigned
04-18-2008, 10:55 PM
I take it you've tried the simplified version of the code?

By the simplified version, do you mean the jumping back and forth between two frames as opposed to using an onEnterFrame? If so, then yes, I have and I've moved on to this.


Do you have the page url to show? I'm curious to see this, maybe I'll understand better. I'm not sure I can answer this, but I still don't know why you need to add the three movieclip sizes together, and then use the entire filesize. It seems (in my understanding) that you are actually adding up the total twice.

As of right now, no I don't. The fact that I had other images being loaded with the root is not the issue here. Those other images are being loaded based off of an xml file so that the client can change the pictures that will show on top of the *.flv file. (Think of a television news anchor with a picture about the news story to the side of him. The client, who is speaking in the film wants to have pictures that he's uploaded to show as he's talking.) So, in order for the pictures to be guaranteed to show up at the right time and actually be there, I made the preloader check to see if they're all loaded.

The question I have is that, if you just had a normal flash file with no outside resources being loaded in (the only elements in the *.swf are the ones that were in the library at compile time), why, when you only have a small vector progress bar, will it not display right off and show the progress of the whole movie being loaded? As it stands right now, if I use a bitmap for a background (or have some large file in the next frame), the preloader will only appear once the *.swf file has already loaded about 40-60%.

What about the procedures that Flash uses to download *.swf files do I need to know or know better to be able to make the preloader show at 1%?

gnomeontherun
04-18-2008, 11:29 PM
By simplified I meant the code I posted that reduced the math.

Can you post the FLA? Just remove the big images and put some kind of placeholder so I can see the structure. It doesn't make sense, which is why I want to see the structure of the file.

aWishResigned
04-18-2008, 11:46 PM
Since I'm talking about all *.fla files in general, I made a quick and dirty one for you. Run it, drop the simulation speed down to 56k and simulate the download. The preloader doesn't show until about 25-26%.

Can't seem to upload it here so the url is: http://www.globalnetdesigns.com/stephen/test.zip

gnomeontherun
04-18-2008, 11:57 PM
Ok I get your question.

http://www.senocular.com/flash/tutorials/faq/

If your file isn't all that large, then the swf might have a larger percentage of the file loaded before getting rendered on the page. So by the time enough of the SWF is loaded to play the first frame, it might have already gotten more than enough loaded to set your bar above 0%.

aWishResigned
04-21-2008, 07:14 PM
Thanks. Got what I needed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum