A Flash Developer Resource Site

1. ## setInterval oddity

whan I use this code to make mc fade out, I got alpha value change in about 1.27 every step instead of 1.

code:
function change_alpha()
{
mc._alpha --
trace(mc._alpha)
}

setInterval(change_alpha,50)

mc fades allright but what with the decimal fraction?
Fish

2. This is because internally, alpha is stored as value that goes from 0-255
(it's an 8-bit binary value). It's done this way because it's faster to the arithmetic since the R,G,B values of the colors are also 8-bit values.

Consider the following:

mc._alpha = 76;
trace(mc._alpha); // result: 75.78125

76 gets converted internally to an integer from 0-255.

76/100 * 256 = 194 (plus some change).

194/256 * 100 = 75.78125

look familiar?

This means that you can actually step the alpha down by less than 1, if you want. The smallest step you can make is 1/256 converted to a 1-100 scale or 100/256 (.390625)

Consider the following code, which steps the alpha down by this step...

code:

function change_alpha()
{
mc._alpha -= 100/256;
trace(mc._alpha)
}

setInterval(change_alpha,50);

Results are:

99.609375
99.21875
98.828125
98.4375

- Jim

3. Thanx

#### Posting Permissions

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

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap