I was working on a project today and I was getting NaN as a return value for a trace up until a certain point in time. I figured that a quick check in an if/else statement would solve my issue but I was wrong. Here I will outline what I initially did and the quick and easy fix for it.
My initial code was this:
var per:Number = ($percent == NaN) ? 0 : ($percent * 100);
That will throw you the following compiler error (even though your app will still run): Warning: 1098: Illogical comparison with NaN. This statement always evaluates to false.
I was a little puzzled so I quickly loaded up the handy ActionScript Error Repository and searched for 1098. Unfortunately, as you can see, error 1098 is not the error I was getting. I don't know if the error is on Adobe's part or on the site's part but I went back to the main page and searched for Compiler Warnings around 1098. I then realized I was no longer on the error site and actually on the Adobe site for Compiler Warnings which listed my issue under 1099. Good job on that one, Adobe!
Anyway, as you can see under the listing for 1099, you can use the global isNaN() method to do the check properly. The revised code is as follows:
var per:Number = (isNaN($percent)) ? 0 : ($percent * 100);
I'm a bit embarrassed that I didn't know about the isNaN() method in the first place but hopefully this saves someone some time in the future and keeps me aware of those pesky little global methods.