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

1162 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 :)

8378 posts Community Moderator
  • Has referred 10+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Attended one of our Meetups around the world
+9 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) + "%";

:)

1682 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
+6 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

8378 posts Community Moderator
  • Has referred 10+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Attended one of our Meetups around the world
+9 more
MSFX Moderator says

you should have a read of this…

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

:)

1682 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
+6 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 7 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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by