3 Replies Latest reply on Mar 3, 2008 5:15 PM by Newsgroup_User

    Please help with preloader

    Level 7
      Now I have made the preloader based on one frame (the preloader itself and
      Actionscript is on frame 1);

      As you can see (in the code) I want the movie clip to decrease it's position
      on the Y axis by 9,5px every time another 10% are loaded. So, from 0 to 100%
      loaded it must move 10 times. But it's not working.

      I assume it would work as expected, but I'm getting more than one instance
      of the same %;
      This way, for example, when 10% are loaded movie clip's _y position
      decreases by 28.5px (three times) instead of 9,5px.


      And here is the code:
      __________________________________
      stop();

      this.onEnterFrame = function(){
      var amount:Number = Math.round(this.getBytesLoaded() / this.getBytesTotal()
      * 100);
      if(amount == 10){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 20){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 30){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 40){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 50){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 60){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 70){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 80){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 90){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      }else if(amount == 100){
      //trace(amount);
      _root.logo_mask._y -= 9.5;
      this.gotoAndPlay(3);
      delete this.onEnterFrame;
      }

      }
      __________________________________

      And here are the trace results of the "amount":

      10
      10
      10
      30
      30
      30
      30
      40
      40
      40
      40
      50
      50
      50
      60
      60
      60
      60
      60
      60
      70
      70
      70
      70
      70
      70
      80
      80
      80
      80
      80
      80
      90
      90
      90
      90
      90
      100


      Any ideas?

      Thanks in advance,
      B.

        • 1. Re: Please help with preloader
          Level 7
          >>I assume it would work as expected...

          Well, you know what they say about assuming. :)

          First of all, loading something (even from a hard drive) is asynchronous.
          Also, the download speed drifts. So, you can never guarantee you'll hit a
          given number. If you were using a simple counter, and incremeted it by 1
          each frame, then your code would work, though it could be much simplified
          (check out the mod operator), but this is not the case - you're not
          incrementing by 1 each frame. For things like this you always have to test
          for >= and not ==.

          One solution is to use a target value and then test to see if you're on or
          past the target. When you are, do your thing and reset the target.

          Try this:

          var target = 10;
          this.onEnterFrame = function(){
          var amount = Math.round(this.getBytesLoaded() / this.getBytesTotal() *
          100);
          if(amount >= target){
          _root.logo_mask._y -= 9.5;
          target += 10;
          }
          if(amount >= 100){
          delete this.onEnterFrame;
          }
          }


          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Please help with preloader
            Level 7
            Yeah!

            Thanks a lot :)
            I was trying to make this out for aloust a week, converting values, etc. But
            never thought taht it could be that easy..

            Thanks once more!
            B.

            "DMennenoh **AdobeCommunityExpert**" <dave@blurredistinction.com> wrote in
            message news:fqgpak$i6m$1@forums.macromedia.com...
            >>>I assume it would work as expected...
            >
            > Well, you know what they say about assuming. :)
            >
            > First of all, loading something (even from a hard drive) is asynchronous.
            > Also, the download speed drifts. So, you can never guarantee you'll hit a
            > given number. If you were using a simple counter, and incremeted it by 1
            > each frame, then your code would work, though it could be much simplified
            > (check out the mod operator), but this is not the case - you're not
            > incrementing by 1 each frame. For things like this you always have to test
            > for >= and not ==.
            >
            > One solution is to use a target value and then test to see if you're on or
            > past the target. When you are, do your thing and reset the target.
            >
            > Try this:
            >
            > var target = 10;
            > this.onEnterFrame = function(){
            > var amount = Math.round(this.getBytesLoaded() / this.getBytesTotal() *
            > 100);
            > if(amount >= target){
            > _root.logo_mask._y -= 9.5;
            > target += 10;
            > }
            > if(amount >= 100){
            > delete this.onEnterFrame;
            > }
            > }
            >
            >
            > --
            > Dave -
            > Head Developer
            > http://www.blurredistinction.com
            > Adobe Community Expert
            > http://www.adobe.com/communities/experts/
            >

            • 3. Re: Please help with preloader
              Level 7
              Glad it helped.

              --
              Dave -
              Head Developer
              http://www.blurredistinction.com
              Adobe Community Expert
              http://www.adobe.com/communities/experts/