Groups | Blog | Home
all groups > flash (macromedia) > september 2006 >

flash (macromedia) : TextInput and Integers


A584537
9/22/2006 9:27:54 PM
Hi, I've spent the past hour or two trying to figure something out.
I have to textinputs, one called "Adults" and one called "Children". The point
of the flash file is to get the number of adults and children. I thought it
would be so easy :)

I thought: [b]var total1=(adults*6)+(children*3);[/b] would work, but it
didn't.
Then I experimented with [i]Number()[/i] and [i]parseInt()[/i] and
[i]int()[/i] and I still can't get anywhere.

I just want to get the numbers from both textinputs then change a Dynamic Text
box to [i]total1[/i].

Could somebody help me please? :)
Rothrock
9/22/2006 11:48:27 PM
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.

trace(parseInt(Adults.text));

That should work.
A584537
9/23/2006 12:00:00 AM
[i]on(rollOver)
{
trace("Hello");
trace(parseInt(adults.text));
}[/i]
My trace isn't working. When I run this in Debug mode, nothing prints out in
Output (F2). Also, when I do: [b] total=total1; [/b] It is always NaN (not a
number) even though I use var total1:Number and parseInt(adults.text);

var total1:Number=parseInt(adults.text)+parseInt(children.text);
total=total1;

Total is the dynamic text box.
Rothrock
9/23/2006 12:00:00 AM
Do this.

trace(Adults.text);

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.
A584537
9/23/2006 11:37:14 AM
I have done this:

on(rollover)
{
trace(adults.text);
}

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 [i]Slide1[/i] 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 [b]trace(name);[/b]
and [b]trace(name.text)[/b] and nothing (text was in the box).
trace("hello"); didn't work either.
It seems I have a new problem :(
AddThis Social Bookmark Button