ActionScript 3 - How do I get my String to convert to a Number?
I have a Budget field (called txtBudget) where I want users to enter a
number value. I then want to store what they entered as a variable
(totalBudget) so that I can perform calculations based on it later.
My problem right now is that when I go to a different frame, and then
return to the frame with the code, the text field displays "NaN". I can't
work out why, and it's driving me mental.
On frame 1 I say:
var totalBudget:Number = 0;
Then on frame 14 I tried:
onBudgChange(null);
txtBudget.addEventListener(Event.CHANGE, updateBudget);
function updateBudget(event:Event):void {
totalBudget = Number(txtBudget);
}
function onBudgChange(event:Event):void {
txtBudget.text = totalBudget.toString();
}
And when that didn't work I looked around and saw a post that said my text
field wasn't a string, and that I needed a variable to convert it. So I
tried this (with no luck):
onBudgChange(null);
var budgetBridge = String(txtBudget);
txtBudget.addEventListener(Event.CHANGE, updateBudget);
function updateBudget(event:Event):void {
totalBudget = parseFloat(budgetBridge);
}
function onBudgChange(event:Event):void {
txtBudget.text = String(totalBudget);
}
I've been pulling my hair out, so any help you can give me would be
greatly appreciated.
No comments:
Post a Comment