Your code looks fine syntactically, so if it's not working, then something else is the culprit, probably something is preventing that code from every executing. Throw a trace statement in right after that line just to see what you get:
code:
trace(mcpreload.loadBar._width); // output?
Here's a trick you may find useful: if you make loadBar the full size (i.e. what it will be when the content is loaded 100%), then you can _xscale to work with the width in percentage. So if your loadBar is a total of 250 px wide when fully loaded, this will set your loadbar to only 1 percent of that full size:
code:
mcpreload.loadBar._xscale = 1;
Likewise, this will set it to 50 percent:
code:
mcpreload.loadBar._xscale = 50;
Since you work with percentage, you can change the size of your loadbar and the code will always work just right, no matter what the size. It's also nice if you get the percentage of bytes loaded and save percentage in a variable because you can always set the loadBar's _xscale to that percentage and it will make the loadBar only that big:
"I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass
Here's more of my (frame) code - maybe this will help:
Code:
stop();
mcpreload._visible = false;
// flag is a file loading.
fileLoading = false;
function loadAudioFile(theURL) {
loadMovie(theURL, "mcholder1");
if (!fileLoading) {
fileLoading = true;
mcpreload._visible = true;
loaderInterval = setInterval(loadChecker, 50);
}
}
function loadChecker() {
loading = mcholder1.getBytesLoaded();
total = mcholder1.getBytesTotal();
percent -= (percent-((loading/total)*100))*.25;
per = int(percent);
mcpreload.loadBar._width = per * 2;
if (percent > 99) {
mcpreload.loadBar._width = 1;
mcpreload._visible = false;
mcholder1.gotoAndStop("loaded");
fileLoading = false;
clearInterval(loaderInterval);
}
}
btn1.onRelease = function() {
loadAudioFile("../flash/clip1.swf");
};
btn2.onRelease = function() {
loadAudioFile("../flash/clip2.swf");
};
Basically what's goin on here is that I load an external movie and a preloader plays, the preloader's width gets set to 200. When I try to load another movie after that, the preloader's width goes from 200 back to 1 and then loads, whereas I'd like to have it just start back at 1. Is there a way to reset a movie clip? I tried setting loadBar's width back to one (traced it also and it was reading as 1) but it doesn't seem to work. See the loadbar comes back up as being filled (aka 100 percent downloaded) and then shoots to like 1 percent and counts back to 100 percent. Any ideas?
I've updated my code..as you'll see below, I now load the preloader into a level...I reset the preloader variables to 0 each time the function to load it is called..is there an easier way to do this? If anyone knows, please advise, thanks!
Code:
stop();
// flag is a file loading.
fileLoading = false;
function loadAudioFile(theURL) {
loadMovie(theURL, "mcholder1");
loadMovieNum("../flash/preloader.swf", 1);
loading = 0;
total = 0;
percent = 0;
per = 0;
if (!fileLoading) {
fileLoading = true;
loaderInterval = setInterval(loadChecker, 50);
}
}
function loadChecker() {
loading = mcholder1.getBytesLoaded();
total = mcholder1.getBytesTotal();
percent -= (percent-((loading/total)*100))*.25;
per = int(percent);
_level1.loadBar._width = per * 2;
if (percent > 99) {
unloadMovieNum (1);
mcholder1.gotoAndStop("loaded");
fileLoading = false;
clearInterval(loaderInterval);
}
}
btn1.onRelease = function() {
loadAudioFile("../flash/clip1.swf");
};
btn2.onRelease = function() {
loadAudioFile("../flash/clip2.swf");
};
"I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass
what I'm trying to do is make the variables inside the 'loadChecker' function local variables so that after the function runs they 'die' and then when I run it again they will be reset...here's what I've done inside the loadChecker function:
Code:
var loading = mcholder1.getBytesLoaded();
var total = mcholder1.getBytesTotal();
var percent -= (percent-((loading/total)*100))*.25;
var per = int(percent);
I get an error when I try this saying that a ';' is expected in the 'var percent -= (percent-((loading/total)*100))*.25;' line.
Any suggestions? Will what I'm trying to do work? What am I doing wrong?
I was actually wondering about that percent line, thinking that it might throw an error. Try this:
code:
var percent = (percent-((loading/total)*100))*.25;
I removed the minus sign because doing something like
code:
percent -= 5;
is a shorthand for this:
code:
percent = percent - 5;
So by having the -= in that line and then also having percent - .... was redundant. Anyways, let me know if removing that minus sign works or not. The rest of your code looks good, which is why I'm confused.
"I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass
I've tried changing the -= operator to a = operator, but it causes the preloader bar script I use not to work. Is there any other way to turn that variable into a local variable?
"I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass
"I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass