Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom loader not working ;(

Status
Not open for further replies.

Supra

Programmer
Dec 6, 2000
422
US
I'm starting to get really pissed with this one! I have some simple code I wrote to determine what percentage of my Flash movie is loaded, and all I want to do is display a little progress bar, but for some reason it's not working. Neither the progress bar nor the text box displayed above it are being updated. Here's the code:
Code:
ifFrameLoaded(120) {
	//gotoAndPlay(4);
}

var loaded = Math.floor((_root._framesloaded / 120) * 100);
_root.ProgBar._width = loaded * 2.21;
_root.TipText.text = loaded + "%";
The progress bar takes the percentage loaded times 2.21 because 221 is the max width I want. The TipText text box sets itself to 1% but doesn't change again until 100%, and the progress bar stays at 0.55 width and doesn't change again until 221 width. This is very confusing and frustrating.. any ideas PLEASE :(
 
make your bar (ProgBar) a movie clip with the instance name ProgBar which im assuming you hav already done, inside it make a rectangle of colour the exact size you want your bar.

back on the main stage make a dynamic text box and give it the var name TipText which again im assuming you've already done

stretch them both over two keyframes and use the following code in frame 2:

myLoaded = Math.round(getBytesLoaded());
myTotal = Math.round(getBytesTotal());
myPercent = myLoaded/myTotal;
ProgBar._width = myPercent*221;
TipText = Math.round(myPercent*100)+"%";
if (myLoaded == myTotal) {
gotoAndPlay(3);
} else {
gotoAndPlay(1);
}


the line ProgBar._width = myPercent*221 is the maximum width of your progress bar when the movie is loaded so if you make it *100 your bar will be 100px long at 100%

the code will stop the movie going onto frame 3 (which is where you would have the start of your flash movie) unitil its fully loaded
 
unless your using flash 8 with action script 2
then use this one instead...

if (_root.getBytesTotal() != _root.getBytesLoaded()){
gotoAndPlay(1);
}
ProgBar._xscale=(_root.getBytesLoaded()/_root.getBytesTotal())*221;
TipText.text=Math.round((_root.getBytesLoaded()/_root.getBytesTotal())*100)+"%";


if you are using this one the dynamic text box needs the instance name of TipText not the variable name!
 
Well the issue was indeed the way I was checking how much of the movie was loaded. Using the suggested _root.getBytesLoaded() and _root.getBytesTotal(), it works perfectly. Here's the end result:
Code:
ifFrameLoaded(120) {
	//gotoAndPlay(4);
}

var loaded = Math.round((_root.getBytesLoaded()/_root.getBytesTotal())*100);
Gauge._width = loaded * 2.21;
Tip.text = loaded + "%";

//And of course in the 2nd frame, it shoots you back to the first :)
THANK YOU, B52AlphaJackal, for my sanity has returned. That's worth a star for sure.
 
glad its sorted mate! its bad enuf when sumfin wont work! but its worse when sumfin wont work and you cant figure out why! haha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top