This content has been marked as final. Show 5 replies
Well as I think you guessed, TEXT fields have TEXT values. Crazy huh? :)
You say you've experimented with parseInt() and aren't getting anywhere. That is odd, because that is the answer. (Assuming you want an integer!) My guess is that you aren't getting the value of the textField. Remember that to get the contents of a text field, as opposed to some other property of the field you need to do this.
trace("The value of the Adults field is "+Adults.text);
But that is text (a string, not a number) even though it looks like a number. To get the number.
That should work.
My trace isn't working. When I run this in Debug mode, nothing prints out in Output (F2). Also, when I do: total=total1; It is always NaN (not a number) even though I use var total1:Number and parseInt(adults.text);
Total is the dynamic text box.
If that doesn't come back with something that at least looks like a number then the problem is something along the lines of there is no text field called Adults, the text field isn't in the timeline you were thinking, the value hasn't been input yet, or something else. Because if there is a text field called Adults and it has a number in it, the code you have shown will work.
I have done this:
And nothing is output(ted?). The two text boxes are all lowercase so I didn't make a mistake in the names when I did something like this. So it should work. On the input boxes children and adults their Var's are named respectively and I just changed the Instance name to the same and that still didn't work.
I'm pretty new to this (as you can probably tell :) ) so I might be overlooking something pretty silly.
Everything is in Slide1 and all the code and input boxes and the button are in the same frame, frame 3.
I just went back to frame 1 to check if trace works there and it doesn't. I have 4 input boxes in Frame 1, one is called name; so I did trace(name); and trace(name.text) and nothing (text was in the box).
trace("hello"); didn't work either.
It seems I have a new problem :(
Edit: If I drag out a TextInput box and set the var attribute in the properties box to adults. Why can't I use adults.text?
If I set the instance name to adults, then the box just has _level0.adults in it and I have to delete it before I enter anything.
Edit2: If I do total=adults.text; (total being a dynamic text box, and I can't set total.text because it doesn't show anything on screen if I change it) anyway, if I do that, the dynamic text box always shows "undefined".
If you restrict the input to just numbers, you can just do this:
var numChildren:int = int(children.text);
var numAdults:int = int(adults.text);
Simple enough, it just might work!
Did that solve it?