PDA

View Full Version : optimize me please :p



pensamente
March 29th, 2005, 12:25 PM
bLoaded = _parent.getBytesLoaded();
bTotal = _parent.getBytesTotal();
perc= (bLoaded/bTotal)*10;
if (bLoaded<bTotal) {
_parent.stop();
percentloaded = Math.ceil(perc);
} else {
this.gotoAndStop(1);
_parent.play();
}
////////////////////////////////////////
/////////////ledzon/////////////////////
////////////////////////////////////////
if (percentloaded>"1") {
led1._visible = 1;
} else {
led1._visible = 0;
}
if (percentloaded>"2") {
led2._visible = 1;
} else {
led2._visible = 0;
}
if (percentloaded>"3") {
led3._visible = 1;
} else {
led3._visible = 0;
}
if (percentloaded>"4") {
led4._visible = 1;
} else {
led4._visible = 0;
}
if (percentloaded>"5") {
led5._visible = 1;
} else {
led5._visible = 0;
}
if (percentloaded>"6") {
led6._visible = 1;
} else {
led6._visible = 0;
}
if (percentloaded>"7") {
led7._visible = 1;
} else {
led7._visible = 0;
}
if (percentloaded>"8") {
led8._visible = 1;
} else {
led8._visible = 0;
}
if (percentloaded>"9") {
led9._visible = 1;
} else {
led9._visible = 0;
}


this is part of a preload that I'm doing. cause I'm trying to get along with this "for" and "function" I thought that all this poem could be write in a simple way... but how :hangover:?

* i've in stage all the "led..." mcs, waiting to be "_visible"

tks

virusescu
March 29th, 2005, 01:05 PM
Something like this.


bLoaded = _parent.getBytesLoaded ();
bTotal = _parent.getBytesTotal ();
perc = (bLoaded / bTotal) * 10;
if (bLoaded < bTotal) {
_parent.stop ();
percentloaded = Math.ceil (perc);
} else {
this.gotoAndStop (1);
_parent.play ();
}
/////////////////////////////////////
/////////////ledzon//////////////////
/////////////////////////////////////
for (x = 1; x < 10; x++) {
if (percentloaded > x) {
this["led" + x]._visible = true;
} else {
this["led" + x]._visible = false;
}
}

pensamente
March 29th, 2005, 01:26 PM
that's right :D
I've tried something similar, but it didn't work...
perc = (bLoaded / bTotal) * 100;


this was the reason why :ko:

thanks

virusescu
March 29th, 2005, 02:33 PM
then change the if (percentloaded > x) {
to if (percentloaded > x*10) {

I recon that you have only 10 leds and after passing 10 percent's loaded you want the first one to load. This should work ;)