PDA

View Full Version : Error in fuction


zbuben
11-18-2009, 11:12 PM
HI, I have an error in a fuction. thanks...

*****
public static function forceInt(arg1:int, arg2:int):int
{
if (arg1 == undefined)
{
return arg2;
}
if (arg1 <= 0 || isNaN(arg1))
{
return arg2;
}
return arg1;
}// end function
*****
I have a bad english...XD

marco.rossi
12-11-2009, 05:00 PM
Could you please post the error also ?

I don't think that the code
if (arg1 == undefined)
is necessary because the arguments will be coerced to int before calling the function.

Barna Biro
12-11-2009, 05:56 PM
Well, you are using an "int"... implicitly, that means that an "int" can't be "NaN", nor can it be "undefined" because it's default value is 0. So the checking you are doing in your method is totally senseless. Although your method is totally senseless, it should only display few warnings at most.

So, I'm guessing that the problem is somewhere else. As marco pointed out, posting the exact error message will definitely help ( or at least, it should help more than what you've posted ). But taking in consideration that this thread is a bit old, maybe you have already figured all the above out...