11 Replies Latest reply on May 8, 2008 10:20 AM by Rapatski

    Filthy _alpha values: -2.874 ...why?!?

    Rapatski
      Dear all,

      I'm pretty puzzled. How can Flash, who has always served me as a loyal calculator make such a mess?

      this.mc.onEnterFrame = function() {
      trace(this._alpha);
      this._alpha--
      }

      traces this:

      100
      98.828125
      97.65625
      96.484375
      95.3125
      94.140625
      etc.

      Why?!!
        • 1. Re: Filthy _alpha values: -2.874 ...why?!?
          Level 7
          Rapatski,

          > I'm pretty puzzled. How can Flash, who has always served me as
          > a loyal calculator make such a mess?

          Heh. Flash is loyal as long as you're calculating within its limits.
          ;) Don't try to calculate anything beyond 15 significant digits.

          > trace(this._alpha);
          > this._alpha--
          > ...
          > traces this:
          >
          > 100
          > 98.828125
          > 97.65625

          The _alpha property is stored internally as a range from 0 to 255. When
          Flash gives you that 0 to 100 range, it's giving you a translation.

          Sham Bhangal mentions a work-around in his Flash Hacks (O'Reilly) book,
          in which you create a stand-in variable, decrement (or increment) that, then
          use that variable to set the _alpha property.

          mc.alphaStandin = 100;
          mc.onEnterFrame = function():Void {
          trace(this.alphaStandin);
          this.alphaStandin--;
          this._alpha = this.alphaStandin;
          }


          David Stiller
          Co-author, Foundation Flash CS3 for Designers
          http://tinyurl.com/2k29mj
          "Luck is the residue of good design."


          • 2. Filthy _alpha values: -2.874 ...why?!?
            Ned Murphy Adobe Community Professional & MVP
            That's interesting... worth a little digging... it's even more inconsistent if you try:

            var Direction = 1;

            this.onEnterFrame = function() {
            trace(this._alpha);
            this._alpha -= Direction;
            Direction *= -1;
            }

            When reducing it drops ~1.2, but when increasing it only rises ~0.8

            output:

            100
            98.828125
            99.609375
            98.4375
            99.21875...

            Maybe it has a built-in easing of some odd sort?
            • 3. Re: Filthy _alpha values: -2.874 ...why?!?
              Rapatski Level 1
              Haha unbelievable.. the first time in ages I visit the boards again and within minutes it's David that answers my question...

              Thanks,
              Tiemen
              • 4. Re: Filthy _alpha values: -2.874 ...why?!?
                kglad Adobe Community Professional & MVP
                actually _alpha varies from 0 to 256, not 0 to 255. it would seem like it should vary from 0 to 255, but it doesn't.

                anyway, ds is correct: you're all seeing the numbers you're displaying because of rounding.
                • 5. Re: Filthy _alpha values: -2.874 ...why?!?
                  Level 7
                  HA! I thought that username looks familiar ... but I didn't put
                  two-and-two together.


                  David
                  stiller@quip.net


                  "Rapatski" <webforumsuser@macromedia.com> wrote in message
                  news:fvtukc$2cq$1@forums.macromedia.com...
                  > Haha unbelievable.. the first time in ages I visit the boards again and
                  > within minutes it's David that answers my question...
                  >
                  > Thanks,
                  > Tiemen


                  • 6. Re: Filthy _alpha values: -2.874 ...why?!?
                    Level 7
                    kglad,

                    Not saying I doubt your findings, but I'm curious how you arrive at 0 to
                    256? I checked Sham's book again and he (perhaps incorrectly) states 0 to
                    256, which makes immediate sense to me because 256 is 2 to the 8th power.


                    David Stiller
                    Adobe Community Expert
                    Dev blog, http://www.quip.net/blog/
                    "Luck is the residue of good design."



                    "kglad" <webforumsuser@macromedia.com> wrote in message
                    news:fvu3o5$6vp$1@forums.macromedia.com...
                    > actually _alpha varies from 0 to 256, not 0 to 255. it would seem like it
                    > should vary from 0 to 255, but it doesn't.
                    >
                    > anyway, ds is correct: you're all seeing the numbers you're displaying
                    > because of rounding.
                    >


                    • 7. Re: Filthy _alpha values: -2.874 ...why?!?
                      Level 7
                      Well, I screwed up that reply, didn't I? :-p

                      Sham's book says 0 to 255, which is a range of 256 values, hence 2 to
                      the 8th.


                      David Stiller
                      Adobe Community Expert
                      Dev blog, http://www.quip.net/blog/
                      "Luck is the residue of good design."


                      • 8. Re: Filthy _alpha values: -2.874 ...why?!?
                        kglad Adobe Community Professional & MVP
                        test in flash.

                        create a movieclip assign its alpha to any multiple of 1/255 and then trace that mulitple of 1/255 and trace the alpha. they'll be different (by 1/255-1/256, unless the multiple is zero or less or greater than 100).

                        now test using any multiple of 1/256.

                        and i agree, it should be 0 to 255. but it's just not. if jeckyll were still here he could probably tell us why.
                        • 9. Re: Filthy _alpha values: -2.874 ...why?!?
                          Level 7
                          kglad,

                          > create a movieclip assign its alpha to any multiple of 1/255 and
                          > then trace that mulitple of 1/255 and trace the alpha. they'll be
                          > different (by 1/255-1/256, unless the multiple is zero or less or
                          > greater than 100).

                          Heh.

                          > now test using any multiple of 1/256.

                          Yep. Can't argue with that.

                          > and i agree, it should be 0 to 255. but it's just not. if jeckyll were
                          > still here he could probably tell us why.

                          I miss jeckyll. His _alpha has been 0 for a while now.


                          David Stiller
                          Adobe Community Expert
                          Dev blog, http://www.quip.net/blog/
                          "Luck is the residue of good design."


                          • 10. Re: Filthy _alpha values: -2.874 ...why?!?
                            kglad Adobe Community Professional & MVP
                            yes, jeckyll brought a unique perspective and knowledge base to the discussion.
                            • 11. Re: Filthy _alpha values: -2.874 ...why?!?
                              Rapatski Level 1
                              Pff, give me a chance. Now I know this, it surely can't be long for some very unique perspective to be coming from this corner... ;)