348 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • India
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
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
  • Author had a Free File of the Month
  • Bought between 10 and 49 items
  • Exclusive Author
  • Grew a moustache for the Envato Movember competition
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • United Kingdom
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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • India
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
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

1161 posts
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 50 and 99 items
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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • India
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
Shaan_007 says

thanks that works :)

8186 posts Community Moderator
  • Attended a Community Meetup
  • Community Moderator
  • Has been a member for 6-7 years
  • United Kingdom
  • Contributed a Tutorial to a Tuts+ Site
  • Won a Competition
  • Contributed a Blog Post
  • Beta Tester
  • Bought between 50 and 99 items
+4 more
MSFX Volunteer 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) + "%";

:)

1676 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 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

8186 posts Community Moderator
  • Attended a Community Meetup
  • Community Moderator
  • Has been a member for 6-7 years
  • United Kingdom
  • Contributed a Tutorial to a Tuts+ Site
  • Won a Competition
  • Contributed a Blog Post
  • Beta Tester
  • Bought between 50 and 99 items
+4 more
MSFX Volunteer moderator says

you should have a read of this…

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

:)

1676 posts Envato Elite Author
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Author had a Free File of the Month
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Has been a member for 4-5 years
  • Referred between 10 and 49 users
+1 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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 7-8 years
  • Netherlands
  • Referred between 50 and 99 users
  • Sold between 1 000 and 5 000 dollars
Yvo says

Great tip MSFX ! Cheers

by
by
by
by
by
by