Click to See Complete Forum and Search --> : change alpha using integers
Big 'Un
03-31-2008, 10:06 AM
I have a simple script that fades a MC in or out.
All I want to do is decrease the alpha gradually by .1.
But it seems to be decreasing by many decimal places, rather than just -.1;
Is there a way to use only whole numbers like .8 as opposed to .723342?
Thanks, all.
Example:
var fade:Number = -.1;
box_mc.alpha += fade;
5TonsOfFlax
03-31-2008, 10:42 AM
.8 isn't a whole number.
alpha only has 255 (I think. Could be a different number) different available values between 0 and 1, and it simply picks the one closest to the number you give it.
Big 'Un
03-31-2008, 11:26 AM
Yes, you're right..."whole number" isn't what I meant.
I guess what I mean is, how can I increment the alpha up or down using only +.1 or -.1. ?
5TonsOfFlax
03-31-2008, 11:36 AM
What you've done is just about as close as you can get. One thing that may avoid compounding of rounding errors would be to keep the current ideal alpha separate from the actual alpha value:
var fade:Number = -.1;
var idealAlpha = 1;
while (idealAlpha >= 0){
idealAlpha += fade;
box_mc.alpha = idealAlpha;
}
The actual alpha values will still end up quantized to the allowed 255 values, but this way you're guaranteed to get the values closest to 1, .9, .8, etc.
Big 'Un
03-31-2008, 11:56 AM
cool!
Thanks.
I'll try it.
flashkit.com
Copyright Internet.com Inc., All Rights Reserved.