yes.. thank you so much.. this helps alot.. (^_^).. i do need to convert the 
string to number coz i have to add it up with values from radiobuttons.. and oh 
yea.. i got one more problem then im done.. sorry if i ask novice questions.. 
im just new to as3.. and willing to learn more.. enhance what i started now..


----- Original Message ----
From: Juan Pablo Califano <[EMAIL PROTECTED]>
To: Flash Coders List <flashcoders@chattyfig.figleaf.com>
Sent: Saturday, May 17, 2008 3:14:48 PM
Subject: Re: [Flashcoders] help again.. NaN

It seems like the TEXT_INPUT event is fired before the .text property is set
with the user's input. So, when you try to read the value from the text
input, it returns an empty string; which, parsed as an integer, returns NaN.

So, you have get the current input char from the event.text field, and check
if the input text has a lenght > 0.

You can try something like this:

stop();

ageField.addEventListener(TextEvent.TEXT_INPUT, convertAge);

function convertAge(event:TextEvent):void {

trace("ageField.text.length:"+ageField.text.length);

var resultTxt:TextField = new TextField();
resultTxt.border = true;
addChild(resultTxt);

var inputChar:String = event.text;

if(ageField.text.length > 0) {
  resultTxt.text = (parseInt(ageField.text) + inputChar).toString();
} else {
  resultTxt.text = inputChar;
}
}
Cheers
Juan Pablo Califano


2008/5/17, Steven Sacks <[EMAIL PROTECTED]>:
>
> Your textfield is probably set to multiline or something like that.
>  Anything like a carriage return will cause parseInt to break.
>
> rlyn ben wrote:
>
>> need to display number to the resultTxt but when i press the first number
>> it displays NaN.. when i enter the second number.. it display the number but
>> with the NaN.. :(
>> stop();
>> ageField.addEventListener(TextEvent.TEXT_INPUT, convertAge);
>> function convertAge (event:TextEvent):Number {
>>  var resultTxt:TextField = new TextField();
>>  resultTxt.border = true;
>>  addChild(resultTxt);
>>
>>  var userAge:Number;
>>  var ageStr:String;
>>  ageStr = ageField.text;
>>   userAge = parseInt(ageStr);
>>  userAge.toString();
>>  resultTxt.text = String(userAge);
>>  return userAge;
>> }
>>
>>
>>      _______________________________________________
>> Flashcoders mailing list
>> Flashcoders@chattyfig.figleaf.com
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>>
>>
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



      
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to