Hi,
I’m building a preloader which only loads the background image. This preloader is inside a MyStage class and it’s something like this:
package...
imports...
public class MyStage{
private var stage:Stage;
private var holder:Sprite;
private var img;
var perc:Number = 0;
private var loader:Loader = new Loader;
private var request:URLRequest;
var __preloaderBar:preloaderBar = new preloaderBar;
function MyStage(stageRef:Stage, url:String){
stage = stageRef;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
request = new URLRequest(url);
configureListeners(loader.contentLoaderInfo);
loader.load(request);
}
private function configureListeners(dispatcher:IEventDispatcher): void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
}
function progressHandler(e:ProgressEvent):void
{
__preloaderBar.width = 0;
__preloaderBar.y = stage.stageHeight / 2;
stage.addChild(__preloaderBar);
perc = e.bytesLoaded / e.bytesTotal;
loader.visible = true;
__preloaderBar.width = perc * stage.stageWidth;
resultado();
}
... Completehandler function ... // long code for stage resizing, not important
function resultado(): Boolean{
trace(perc);
if(perc == 1)
return true;
return false;
}
in my Index class, I have the conditional code:
.
.
.
public function Index():void {
//addEventListener(Event.ADDED_TO_STAGE, init);
var mystage:MyStage
mystage = new MyStage(stage, "image.jpg");
if(mystage.resultado() == true){
init();
}
}
This is the most weird issue I’ve got so far. Remember, I’m calling resultado() on the onProgress function just for test purposes. In theory, it should go on the Completehandler function. Now, when I check if perc is equal to 0, it returns true and loads the image and the rest of content in my index class, but only works with zero.
I have already traced and the perc is increasing as you can see:
0
0.05129879024840807
0.10259758049681614
0.1538963707452242
0.20519516099363228
0.25649395124204033
0.3077927414904484
0.3590915317388565
0.41039032198726455
0.4616891122356726
0.5129879024840807
0.5642866927324888
0.6155854829808968
0.6668842732293049
0.718183063477713
0.769481853726121
0.8207806439745291
0.8720794342229371
0.9233782244713452
0.9746770147197533
1
When it reaches 1, it should return true. But it doesn’t!
Any ideas?
Thanks in advance.