A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: change alpha using integers

  1. #1
    Senior Member Big 'Un's Avatar
    Join Date
    Aug 2004
    Location
    NYC
    Posts
    231

    change alpha using integers

    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;

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    .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.

  3. #3
    Senior Member Big 'Un's Avatar
    Join Date
    Aug 2004
    Location
    NYC
    Posts
    231
    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. ?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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:
    Code:
    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.

  5. #5
    Senior Member Big 'Un's Avatar
    Join Date
    Aug 2004
    Location
    NYC
    Posts
    231
    cool!
    Thanks.
    I'll try it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center