348 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
+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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
+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
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Had an item featured in an Envato Bundle
+4 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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
+3 more
Shaan_007
says

thanks that works :)

8508 posts Community Moderator
  • Located in United Kingdom
  • Has been part of the Envato Community for over 7 years
  • Helps us moderate the forums
  • Won a competition
+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) + "%";

:)

1686 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 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

8508 posts Community Moderator
  • Located in United Kingdom
  • Has been part of the Envato Community for over 7 years
  • Helps us moderate the forums
  • Won a competition
+10 more
MSFX
Moderator
says

you should have a read of this…

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

:)

1686 posts Envato Elite Author
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 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
  • Has been part of the Envato Community for over 8 years
  • Has referred 50+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 1+ items on Envato Market
+2 more
Yvo
says

Great tip MSFX ! Cheers

by
by
by
by
by
by