PDA

View Full Version : debug needed: "preloader for swf files loaded into MC's



avlisdivad
May 23rd, 2002, 02:34 PM
Ok. So I'm loading several content pages (.swf) into blank mc's. And then attempting to control them from _level0 (the original movie).

But the swfs add up to a bit of KB so Id like to make sure they are preloaded before I tell one of them to play (the navigation).

Notes:
-each .swf has a stop on the first frame so it wont start right away.
-blank mc's are already on the stage

Here's where I am....

frame 1:

onClipEvent (enterFrame) {
_root.mc20.loadMovie("navigation.swf")
_root.mc1.loadMovie("home.swf");
_root.mc2.loadMovie("home2.swf");
}

frame 2 (the preload check):

onClipEvent (enterFrame) {
totalBytes = _root.mc1.getBytesTotal()+_root.mc2.getBytesTotal( )+_root.mc20.getBytesTotal();

bytesLoaded = _root.mc1.getBytesLoaded()+_root.mc2.getBytesLoade d()+_root.mc20.getBytesLoaded();

percentLoaded = Math.floor(bytesLoaded/totalBytes*100);

if (percentLoaded>0 && percentLoaded<100) {
_root.bar.gotoAndStop(percentLoaded);

}

if (totalBytes == bytesLoaded) {
_root.mc20.gotoAndPlay("play");
}
}


but..............I cant get it to work.....preload or even play mc20.

thank you,

avlisdivad

upuaut8
May 23rd, 2002, 10:14 PM
you know.. a lot of people have been asking about this. I'll see what I can figure out... no solutions yet.

avlisdivad
May 28th, 2002, 12:46 PM
Ive modeled this preloader off of a few other posts. But none of the threads had answers, so I asked myself!

avlisdivad

upuaut8
May 30th, 2002, 12:59 AM
frame 1:

onClipEvent (enterFrame) {
_root.mc20.loadMovie("navigation.swf")
_root.mc1.loadMovie("home.swf");
_root.mc2.loadMovie("home2.swf");
}

-------------------------
What do you mean by this? It seems as if you're using an onClipEvent in a "frame" action. That wont work. It should look like this at the very least.

mc20.loadMovie("navigation.swf");
mc1.loadMovie("home.swf");
mc2.loadMovie("home2.swf");

as long as your mc1 20 and 2 are all on the main timeline, you don't need the _root extention, and OnClipEvents are reserved for attaching to movie clips.

-------------------------------
frame 2 (the preload check): with notation

//1totalBytes stuff
1totalBytes = _root.mc1.getBytesTotal();
1bytesLoaded = _root.mc1.getBytesLoaded();

//2totalBytes stuff
2totalBytes = _root.mc2.getBytesTotal();
2bytesLoaded = _root.mc2.getBytesLoaded();

//20totalBytes stuff
20totalBytes = _root.mc20.getBytesTotal();
20bytesLoaded = _root.mc20.getBytesLoaded();

//total it up
totalBytes = 1totalBytes+2totalBytes+20totalBytes;
bytesLoaded = 1bytesLoaded+2bytesLoaded+20bytesLoaded ;

//bar manipulation
percentLoaded=Math.floor(bytesLoaded/totalBytes*100);
if (percentLoaded>0&&percentLoaded<100) {
bar._xscale=percentLoaded;
}

if (20totalBytes == 20bytesLoaded&&20totalBytes!=0) {
mc20.gotoAndPlay("play");
}
----------------------------
Note that I used a different kind of bar than you were using. I just make a bar of some length depending upon the stage and such. This script just tells it to scale x. Mind you when I do this I will modify the centerpoint of the bar clip so that it rests on one edge or the other. that way the bar will scale out from that point.
I also added something to the if statements. First, I took the totals from each individual movie clip just to have them handy. If you don't need one, don't bother with that part of the script. But in this case, I think it might be better to take just the 20 movie's loaded and total stats. This way it's not waiting on anything else..
You can easily add more if statements for each of the other clips if you need to.

I also added "&&20totalBytes!=0" to the end of the if statement. Sometimes when a movie first starts playing, it will register as having 0 bytesTotal and 0 bytesLoaded. Hence they are equal, and it tries to get whatever it's waiting on to play or worse goto a frame that doesn't exist yet. So on all of my preloaders I add that to the end of the if statement.


-----------------------------
frame 3

gotoAndPlay(2);

-------------------
You have to loop this script so that frame 2 is played over and over again. that way every frame it gets an update to the size of the bar, and the chance of one of the objects playing.