348 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Collector Level 1
+3 more
Shaan_007
says
i am getting a bit of problem in this code
stop();

this.addEventListener(Event.ENTER_FRAME, loading);

function loading(e:Event):void {

    var total:Number = this.stage.loaderInfo.bytesTotal;
    var loaded:Number = this.stage.loaderInfo.bytesLoaded;

    loader_txt.text = Math.floor((loaded/total)*100)+ "%";

    if (total == loaded) {
        loader_mc.gotoAndPlay(94);
    }
    if (loader_mc.currentFrame==loader_mc.totalFrames) {
        play();
        this.removeEventListener(Event.ENTER_FRAME, loading);
    }

}
after 100% loader_mc dont play from 94 it just get stuck on frame 94 please help
260 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 4
  • Collector Level 2
+4 more
ravenwill
says

I know it sounds weird but it could be due to there being a slight difference between bytesLoaded and bytesTotal, like 0.01 of a diference would make your if statement not fire as they are not the same.

Instead try:

 if (Math.floor((loaded/total)*100) == 100) {
        loader_mc.gotoAndPlay(94);
    }
348 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Collector Level 1
+3 more
Shaan_007
says

if statement is running well because loader_mc loops from frame 1-93 till if statement is fired

But after it is fired loader_mc get stuck (stops) at 94 frame instead of playing

1163 posts
  • Affiliate Level 2
  • Author Level 6
  • Collector Level 3
  • Top Monthly Author
+6 more
FlashTang
says
stop();
var comp
this.addEventListener(Event.ENTER_FRAME, loading);

function loading(e:Event):void {

    var total:Number = this.stage.loaderInfo.bytesTotal;
    var loaded:Number = this.stage.loaderInfo.bytesLoaded;

    loader_txt.text = Math.floor((loaded/total)*100)+ "%";

    if (total == loaded&&!comp) {
      loader_mc.gotoAndPlay(94);
      comp=true
    }
    if (loader_mc.currentFrame==loader_mc.totalFrames) {
        play();
        this.removeEventListener(Event.ENTER_FRAME, loading);
    }

}

348 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Collector Level 1
+3 more
Shaan_007
says

thanks that works :)

8586 posts Community Moderator
  • United Kingdom
  • 7 Years of Membership
  • Moderator
  • Winner
+10 more
MSFX
Moderator
says

since the rounding code is being called so regularly you should optimize and use bitwise math rather than flooring with the Math class, far far faster…

so

loader_txt.text = Math.floor((loaded/total)*100)+ "%";

becomes..

loader_txt.text = (((loaded/total)*100) | 0) + "%";

:)

1689 posts Envato Elite Author
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Top Monthly Author
+8 more
Tean
says

I never use Math.floor when I want to round down, I use int(). Dont know about performance difference, all I know is its much easier to write :P

8586 posts Community Moderator
  • United Kingdom
  • 7 Years of Membership
  • Moderator
  • Winner
+10 more
MSFX
Moderator
says

you should have a read of this…

http://gskinner.com/talks/quick/#48

:)

1689 posts Envato Elite Author
  • Affiliate Level 2
  • Author Level 8
  • Collector Level 1
  • Top Monthly Author
+8 more
Tean
says
you should have a read of this…

http://gskinner.com/talks/quick/#48

:)

There are some good optimization tricks in there! Thanks :)

381 posts
  • 8 Years of Membership
  • Affiliate Level 3
  • Author Level 3
  • Collector Level 1
+2 more
Yvo
says

Great tip MSFX ! Cheers

by
by
by
by
by
by