5 Replies Latest reply on Aug 16, 2007 12:51 PM by Newsgroup_User

    Flash _alpha or EnterFrame Bug?

    gavinnosler
      I ran into a problem and isolated it into a small Flash movie. Just create a new Flash movie, draw a shape, convert it to a MovieClip, and put the attached code onto the MovieClip instance. Basically, I set the _alpha to 0 on Load, then on EnterFrame I either add or subtract by increments of 10. Technically, this should never set the _alpha to anything other than an increment of 10. The result is a bunch of fractional values.

      The purpose of this code is to have a button that is _alpha 20% when the variable "active" is false, or 100% when "active" is true. It starts off at 0%, so it should fade on right away.
      -
        • 1. Re: Flash _alpha or EnterFrame Bug?
          Level 7
          gavinnosler,

          > Technically, this should never set the _alpha to anything other
          > than an increment of 10. The result is a bunch of fractional values.

          This isn't specifically an onEnterFrame bug, per se; in fact, arguably,
          it's not a bug at all. But given that _alpha seems straightforward, yet
          results in seemingly bizarre output, the term "bug" isn't a bad name for it.
          I could go either way. ;) Internally, the MovieClip._alpha property is
          stored as an integer between (and including) 0 and 255. The API gives you a
          range of 0 to 100, presumably as a convenience, but that gets translated
          into the 0 to 255 scale. In order to side-step this issue (yeah, probably a
          bug!) Sham Bhangal recommends an easy workaround in "Flash Hacks" (O'Reilly)
          that I use often. In your enterFrame loop, keep track of the desired alpha
          in a custom variable, incrementing or decrementing that instead of the
          _alpha property directly, then use your variable to set the property.

          onClipEvent (load) {
          _alpha = 0;
          var active:Boolean = false;
          var alpha:Number = 0;
          }

          onClipEvent (enterFrame) {
          if (active) {
          if (alpha<100) {
          alpha += 10;
          _alpha = alpha;
          } // etc.


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


          • 2. Re: Flash _alpha or EnterFrame Bug?
            Damon Edwards Level 3
            use something like this instead of that style of coding. give your Movie clip an instance name of your_mc. click on the frame where it resides, and open the actions panel, make sure it says "Actions-Frame" in the upper left hand corner, paste this code in there.
            • 3. Re: Flash _alpha or EnterFrame Bug?
              Rothrock Level 5
              Well it is all based on how alpha works – and the way it works is the way it works. Flash doesn't keep track of alpha in the same way that we use to set it. Internally Alpha is mapped between 0 and 255 (0x0 and 0xff) So the only places where you will get the exact integers is 0, 25, 50, 75 and 100. Other than that it will all be crazy decimals.

              If you need to keep exact values, then keep them in an external variable, modify that variable then apply it to the _alpha.
              • 4. Re: Flash _alpha or EnterFrame Bug?
                gavinnosler Level 1
                Yep, that's actually what I did to fix the problem.

                It might not technically be a bug, but the result isn't expected, nor correct, so I think Adobe should fix it in the next version.
                • 5. Re: Flash _alpha or EnterFrame Bug?
                  Level 7
                  gavinnosler,

                  > Yep, that's actually what I did to fix the problem.

                  Cool. :)

                  > It might not technically be a bug, but the result isn't expected,
                  > nor correct, so I think Adobe should fix it in the next version.

                  If by "next version" you mean ActionScript 3.0, you'll find that the
                  alpha property is now a range from 0 to 1, so fractions are par for the
                  course. If you mean future versions of Flash Player, who knows? It can't
                  hurt to make mention of it on the official feature request / bug report
                  form:

                  http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform


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