Flash: Inaccuracies in the _alpha property
April 28th, 2005 by LuisHave you ever realized about the rounding error when using the MovieClip._alpha property?
try this:
myMc.alpha=10; trace(myMc.alpha); // Displays 9.765625
This error could be very bad when you use fade transitions, making flash to run sluggishly. In order to avoid performance degradation you could use a Class or prototype that prevents this kind of error simply defining functions that read and write its own property.
Actionscript:
- class AlphaClip
- {
- private var alphaInternal:Number;
- private var target:Object;
- function AlphaClip (mc:Object)
- {
- target = mc;
- alphaInternal = mc._alpha;
- }
- public function get _alpha ():Number
- {
- return alphaInternal;
- }
- public function set _alpha (alphaIn:Number):Void
- {
- target._alpha = alphaIn;
- alphaInternal = alphaIn;
- }
- }
- //usage
- var myAlpha:AlphaClip = new AlphaClip (myMc);
- myMc._alpha=10;
- trace(myMc._alpha); // Displays 9.765625
- myAlpha._alpha=20;
- trace(myAlpha._alpha); // Displays 10
Hack number 19 from Flash Hacks


