Groups | Blog | Home
all groups > flash actionscript > november 2005 >

flash actionscript : _alpha decimals?


radiomouse
11/1/2005 11:10:58 PM
Does anyone know why any increments or decrements to a movieclip's _alpha
property results in a decimal rather than a whole number? Up until now I've
had no problem with this, but I just ran a test and am definitely getting
decimals.

simple code:
blub.onEnterFrame = function(){
trace(blub._alpha);
blub._alpha -= 1;
}

but instead of getting 100, 99, 98, 97, etc. like expected, i'm getting 100,
98.828125, 97.65625, 96.484375, 95.3125, etc., which is pretty annoying. Does
anyone know if this is a bug or if i'm just overlooking something rediculously
simple?
radiomouse
11/1/2005 11:55:50 PM
Jeckyl
11/2/2005 12:00:00 AM
alpha is not a float internally .. its a whole number from 0 up to 256

this gets mapped to a percentage value for access from script.

so setting _alpha = 75 in script gets turns into 75*256/100 = 192 internally
and then if you then look at _alpha it works out 192*100/256 = 75.

however, for most percentages, you don't end up with a 'nice' results like
that .. eg try 90 instead of 75 ..

so setting _alpha = 90 in script gets turns into 90*256/100 = 230.4 = 230 as
whole number internally and then if you then look at _alpha it works out
230*100/256 = 89.84375
--
Jeckyl

Jeckyl
11/2/2005 12:00:00 AM
[quoted text, click to view]
you're welcome.
--
Jeckyl

radiomouse
11/2/2005 12:51:07 AM
AddThis Social Bookmark Button