Forced Preloader

hey, I wonderd if anyone could help me make a forced preloader? My site is small so the preloader would just show up for one second and then go to the site, but i want it to go from 1 to 100, without going like 20 to 80 then done…

Can anyone help? I’ll be very gratefull. My preloader bar will have a width of 200.

Thanks,
fatnslow

lol
textfield instance name myText
bar instance name bar
first frame
stop();
bar._width = 0;
myfunction = function () {
percent += 1;
bar._width += 2;
myText.text = percent+" % Loaded";
if (percent == 100) {
clearInterval(myInterval);
gotoAndStop(2);
}
};
myInterval = setInterval(myfunction, 100);

you can change 100 to adjust the speed

But, does this actually load the page, seems like it just regulate the size of the bar…but I need a real preloader, but that dont just jump from 20 to 80. So it will be a normal preloader, but it takes atleast 2 seconds, and if the user has modem, it will take the loading time…

Sry if it was confusing.

Thanks,
fatnslow

Why put a preloader if it loads quickly.

For the look :slight_smile:

Anyone able to help?

This just seems a little pointless but what you could do is have a fake preloader as outlined above and a genuine one and switch between the 2 dependant upon the speed it initially starts loading.(There are tutorials for measuring this on flashkit and probably here too)

Yah, I guess. But isnt it possible setting so the preloader in the transition just goes from 1 to 100? Usually it just goes from 20 to 80 then done, but I would very much like it to go all the way without to much difficulties…but still actually load the page.
You with me?

I used the transition tutorial here on kirupa.

thanks

sorry , never seen the transition tutorial

Hmm, ok.
Antyone else able to help me change the preloader in the transition tutorial her on kirupa?

Thanks

well… yeah…
have a variable called realPercent which is calculated as outlined on the tutorial for the real preloader, then have this code on frame1 as well:

if(!intervalStarted){
    intervalStarted=1
    fakePercentInt = setInterval(function(){
        fakePercent++
    },100) //again, change the 100 to a speed of your choice ;)
}
if(realPercent<=fakePercent){
    clearInterval(fakePercentInt)
}
else if(realPercent>fakePercent){
     intervalStarted=0
}
else if(realPercent==fakePercent==100){
    gotoAndStop(3)
}
// below is an.... optional... extra ;) lol
else{
    fakePercent = "woops... an error occurred..."
}

and just set your text box equal to the variable fakePercent and have the _width of your preloader bar calculated as 2fakePercent*

that should do the trick neway… (just written as a post, not copied and pasted as tried&tested code…)

Prophet.

Hmm, didnt get that…“have a variable called realPercent”?

your preloader should have somewhere in it something like

percent = (bytesLoaded()/bytesTotal())*100

change it to this:

realPercent = (bytesLoaded()/bytesTotal())*100

then add the codea bove on the first frame.

look at the tutorial again if your still lost…
but then again, if it still doesnt make any sense we could be talking about diff tuts… so post the link and ill look…

Prophet.

Hey, im using this tutorial: http://www.kirupa.com/developer/mx/percentagepreloader.htm

But can’t really get it to work…

Thanks

Ok, in the first frame I now have:


bytesLoaded = Math.round(_root.getBytesLoaded());
bytesTotal = Math.round(_root.getBytesTotal());
//getPercent = bytes_loaded/bytes_total; // Just to remember what the old one was
realPercent = (bytesLoaded/bytesTotal)*100
_root.loadBar._width = realPercent*100;
_root.loadText = Math.round(realPercent*100)+"% Loaded";
if (bytesLoaded == bytesTotal) {
	_root.gotoAndStop(3);
}
if(!intervalStarted){
    intervalStarted=1
    fakePercentInt = setInterval(function(){
        fakePercent++
    },17) //again, change the 100 to a speed of your choice ;)
}
if(realPercent<=fakePercent){
    clearInterval(fakePercentInt)
}
else if(realPercent>fakePercent){
     intervalStarted=0
}
else if(realPercent==fakePercent==100){
    gotoAndStop(3)
}
// below is an.... optional... extra ;) lol
else{
    fakePercent = "woops... an error occurred..."
}

But it doesn’t seem to work…

thats becausse your setting your properties to realPercent which is not what you want, try this:

bytesLoaded = Math.round(_root.getBytesLoaded());
bytesTotal = Math.round(_root.getBytesTotal());
//getPercent = bytes_loaded/bytes_total; // Just to remember what the old one was
realPercent = (bytesLoaded/bytesTotal)*100
_root.loadBar._width = fakePercent*2; //max width is 2*100 = 200 as opposed to what you had as 100*100 = 10000
_root.loadText = fakePercent+"% Loaded"; //no need to round or times as fakePercent is incremented by 1 each time rather than being loaded/total
if(!intervalStarted){
    intervalStarted=1
    fakePercentInt = setInterval(function(){
        fakePercent++
        running=1 //noticed a minor error with my code here...
    },17) //again, change the 100 to a speed of your choice ;)
}
if(realPercent<=fakePercent){
    clearInterval(fakePercentInt)
    running=0
}
else if(realPercent>fakePercent && running==0){
     intervalStarted=0
}
else if(realPercent==fakePercent==100){
    gotoAndStop(3)
}
// below is an.... optional... extra ;) lol
else{
    fakePercent = "woops... an error occurred..."
}

that should werk better :wink:

Prophet.

Hey again, thanks for taking you time to look into this…

But It doesn’t work atm, heres the .fla of my little site.

And if you have time, could you check what wrong with the mp3 player? I get NaN loaded when its online…

Thanks for all the help!,
fatnslow

how about this i didnt look it over that well but it does the thing you wanted so.
Note: prophet you wrote all that code you could of just sent him a fla, hes a visual person i think lol.

yeah i had to fiddle with the failsafes… sorry about that…
heres a working example that (on a slow connection) stops if the realPercent gets behind the fakePercent and restarts if realPercent is at least 5 ahead of fakePercent or if realPercent has reached 100… looks pretty neat if i dont say so myself :wink: lol

bytesLoaded = Math.round(_root.getBytesLoaded());
bytesTotal = Math.round(_root.getBytesTotal());
//getPercent = bytes_loaded/bytes_total; // Just to remember what the old one was
realPercent = (bytesLoaded/bytesTotal)*100
_root.loadBar._width = fakePercent*2; //max width is 2*100 = 200 as opposed to what you had as 100*100 = 10000
_root.loadText = fakePercent+"% Loaded"; //no need to round or times as fakePercent is incremented by 1 each time rather than being loaded/total
if(!firstTime){
	firstTime=1
	fakePercent=0
}
if(intervalStarted!=1){
    intervalStarted=1
	clearInterval(fakePercentInt)
	fakePercentInt = setInterval(function(){
        fakePercent++
		trace(realPercent)
    },20) //again, change the 100 to a speed of your choice ;)
}
if(fakePercent>realPercent){
	clearInterval(fakePercentInt)
}
else if(fakePercent<(realPercent-5)||realPercent>=100){
	intervalStarted=0
}
if(fakePercent>=100){
	gotoAndStop(3)
	clearInterval(fakePercentInt)
}

fraid i cant help u much with the mp3 player… i havent really dabbled in sound yet… nor xml… sorry!

Prophet.

No problem! Thanks very much !

Thanks alot,
fatnslow

Btw, you shouldnt happen to know how I can get this preloader to work for the transitions aswell? Having some problem getting it working.

Thanks,
fatnslow