Be a Supporter!

[AS3] numerical values to textboxes

  • 241 Views
  • 3 Replies
New Topic Respond to this Topic
ChilliTree
ChilliTree
  • Member since: Jan. 1, 2011
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
[AS3] numerical values to textboxes 2011-01-27 15:39:43 Reply

Right this seems really simple and silly but I've had a look at tutorials and can't seem to manage this, in essence all I want to do is make a dynamic text box show a numerical variable on the stage.

So I've made a dynamic text box with the instance name of:

myTextBox

Then I've added this code in the frame:

var textBoxValue:int = 5;

textBox.text = (textBoxValue);

So I'm guessing "text" isn't the right property to use? How do you do it?

Kirk-Cocaine
Kirk-Cocaine
  • Member since: Aug. 17, 2003
  • Offline.
Forum Stats
Moderator
Level 38
Programmer
Response to [AS3] numerical values to textboxes 2011-01-27 15:42:43 Reply

You just need to cast your variable as a string:

textBox.text = String(textBoxValue);

The water in Majorca don't taste like what it oughta.

| AS3: Main | AS2: Main | Flash Tutorials |

BBS Signature
Wurmy
Wurmy
  • Member since: Jun. 20, 2006
  • Offline.
Forum Stats
Member
Level 28
Programmer
Response to [AS3] numerical values to textboxes 2011-01-27 15:42:57 Reply

At 1/27/11 03:39 PM, ChilliTree wrote: Right this seems really simple and silly but I've had a look at tutorials and can't seem to manage this, in essence all I want to do is make a dynamic text box show a numerical variable on the stage.

So I've made a dynamic text box with the instance name of:

myTextBox

Then I've added this code in the frame:

var textBoxValue:int = 5;

textBox.text = (textBoxValue);

So I'm guessing "text" isn't the right property to use? How do you do it?

You're on the right track. The property "text" is the right property to use.

The problem is that "textBoxValue" is an int and that textBox.text is a string and you can't directly convert an int to a string. You'll have to do this:

textBox.text = textBoxValue.toString();

BBS Signature
ChilliTree
ChilliTree
  • Member since: Jan. 1, 2011
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to [AS3] numerical values to textboxes 2011-01-27 15:44:47 Reply

Ah thanks guys, one step at a time ;P