views:

80

answers:

1

i'm trying to determine if a color has been supplied as an optional argument to a function. in order to determine this, i'm simply writing if(color){...} and supplying NaN if i don't want there to be a color.

however, it seems that the color black (0x000000) also equates to NaN. how can i determine if a supplied color number argument is present and black if 0x000000 is passed as the argument?

+4  A: 

Some source code would be appropriate.

It sounds like you are saying that the following are equivalent:

if ( NaN ) {}
if ( 0x000000 ) {}

which is true. I think you want:

if ( isFinite( color ) ) {}

Adobe help: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/package.html#isFinite()

drawnonward
I'm not doubting you, but why is 0x000000 not a number? I thought it would be equal to zero? I searched online and it looks like this is right, but I couldn't find an explanation.
Sandro
It is not that 0 == NaN, it is that NaN in an if statement evaluates to false just like 0 does. NaN has special comparison rules.
drawnonward