PDA

View Full Version : Pathing Question


JRBT
11-30-2004, 09:28 PM
Hi everyone,

I am building a little martgage calculator and am hitting a dead end on a simple pathing issue.

On my stage I have following:

Root Screen - "application"
Child Screen - "mortCalcForm"

Then in the child screen:

button: "calcBtn"
textfield: "numYears"
label: "numYearsLabel"

All I am trying to figure out is how to change the text within the label in the event that the content of the textfield is not a number. Here's the code on my button:


on(click){
//trace(this._parent.numYears.text);
//this._parent.numYearsLabel.text = "Incorrect Format.";
//this._parent.numYearsLabel.setStyle("color", "0xFF0000");

if(Number(this._parent.numYears.text) == "NaN"){
this._parent.numYearsLabel.text = "Incorrect Format.";
this._parent.numYearsLabel.setStyle("color", "0xFF0000");
}
}


If I uncomment the first series of commands, the label text changes, but the statements inside the if condition will not work - I can't figure out why!
I have enclosed the .fla file just in case it exposes the error of my ways.

Thanks in advance!

mmm..pi..3.14..
11-30-2004, 10:25 PM
This seems to work...:)


on (click) {
//trace(this._parent.numYears.text);
//this._parent.numYearsLabel.text = "Incorrect Format.";
//this._parent.numYearsLabel.setStyle("color", "0xFF0000");
if (isNaN(this._parent.numYears.text) == true) {
this._parent.numYearsLabel.text = "Incorrect Format.";
this._parent.numYearsLabel.setStyle("color", "0xFF0000");
}
}

Eric :)

JRBT
12-03-2004, 01:31 PM
I can't believe I had forgotten about the isNAN() function. Thank you.

Can anybody explain then why my first code wasn't working? The number() still should have return either the value or a NaN, right?

Such as:

number("foobar") should return NaN

and

number(69) should return 69, right?

redruby
12-03-2004, 02:29 PM
"NaN" is a string, not a number. Use Number.NaN instead, which is a member of the Number Class.