View Full Version : Preloader progress bar calculation
rockman82
03-10-2007, 04:49 AM
ould someone please tell me what is wrong with this code? I'm making a preloader bar ("loaderbar" in the code) which will extend from 0 pixels to 165 pixels when the load progress reaches 100%. Then the playhead will move to frame 2, triggering the animation, buttons, etc. to be displayed. Right now, nothing quite works, and I haven't found the probelm. Also, if there is a simpler or more efficient way to do this, it would be much appreciated. Thanks.
_root.stop();
_global.Y = 0;
function loadprogress () {
_global.Y = (_root.getBytesLoaded()/_root.getBytesTotal());
_root.loader.loaderbar._width = Math.ceil(_global.Y)*(165);
updateAfterEvent();
};
setInterval (loadprogress, 50);
if (_global.Y >= 1) {
_root.gotoAndPlay(2);
};
WhidbeyTomas
03-12-2007, 11:43 PM
Hey Rockman82, I see that 70 people have viewed your question but exactly zero have responded. That is pretty much the same statistics I get. So I'll give you the benefit of my imperfect wisdom. This will be a little like the myopic leading the myopic, but you'll get what you pay for.
First, if you need a preloader, you are doing something wrong. (Sometimes I do use a preloader just in case, even when the files are too small to activate it) I never create large swf files. Sometimes I have to load a large graphic. In that case, I will load it in parts (overlapping swfs). An example of my strategy for a web page is one swf that provides the background, another with the navigation, and every bit of content is another swf.
I never use scenes. Scenes are a hold-over from the dark ages of CDs.
Ok, about your code, I'll just fish a little here. Your code starts with a stop command. You then introduce a function called loadprogress, but I don't see anywhere that you actually call up this function, so even if your code is fine, if it is not called up, how will it be activated? You might rectify this by using an event handler, such as: onEnterFrame.loadprogress=function(){ function.
Personally, I would create an mc with the preloader on it.
Finally, if you have not done a search for a preloader, you are wasting a lot of time. There must be a million tutorials for this online.
(If I am way off, perhaps I'll awaken a firestorm [we'll get a response one way or another].)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.