| Ultrashock Forums
• [AS3] Fake loader based on time |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
|
2009-07-01
#2 |
||
|
17 Creative Assets
|
2009-07-01
#3 |
||
|
The value of the "percent" variable in the update() function will range from 0.0 to 1.0 inclusive, you can use that value as-is to scale a display object. Code:
var timeStart:int = 0;
var timeTotal:int = 180000; // 3 minutes
startLoad();
function startLoad():void
{
timeStart = getTimer();
addEventListener( Event.ENTER_FRAME, update );
}
function update( e:Event ):void
{
var percent:Number = ( getTimer() - timeStart ) / timeTotal;
if( percent >= 1.0 )
{
percent = 1.0;
removeEventListener( Event.ENTER_FRAME, update );
// load complete
trace( percent, "LOADED" );
}
else
{
// load progress
trace( percent );
}
progressBar.setProgress( percent );
}
|
|
|
2009-07-01
#4 |
||
|
Wonderful Nutrox! In my original thinking I had an interval running every second updating a value and an eventListener to handle the progress. I didn't feel good about that solution that is why I posted
|
|
17 Creative Assets
|
2009-07-01
#5 |
||
|
No problem man. Tiran hit the nail on the head with his reply, I just threw together a working example.
|
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|


Lets say I have a progress bar with a width of 300px. When I set the width/scaleX to zero, how can I increase the width/scaleX based on duration. So if I want the entire load progress to last three minutes, it will take the load bar three minutes to go from zero to either its maximum width (300px) or 100% scaleX?
4 comments
| 118 views



17 Creative Assets
Linear Mode
Calculate how much time has passed. Say 1 minute has gone by. Then you would find out the percentage that 1 minute is of 3 minutes (1 divided by 3). That would give you 0.33. Then all you need to do is times 300 by .33 and your load bar would need to be 99px. Might have to do some rounding in there when you actually tell your load bar how wide to be (so its not a decimal).