00:00
00:00
Newgrounds Background Image Theme

JamesChrist just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS3 How to make text into a number

424 Views | 5 Replies
New Topic Respond to this Topic

I'm trying to make a textbox (instance is box) change into a number on a mouse event.
I made a variable called money, which is a number, and when I try to set box.text = money; it tells me I can't because it is not a string.
How do I make the textbox into a number?


At 8/20/16 06:50 PM, K3ter wrote: when I try to set box.text = money; it tells me I can't because it is not a string.

the term is called Casting, and there's a ton of different ways.

box.text = money.toString();

almot everything in flash has a toString() function. theres also:

box.text = String(money);

Which is the generic way to cast anything to another thing, or it will do it automatically on certain type conversions

var foo:* = 55;
var bar:String = foo;

but if foo was type Number or int, you would get a compile error

and you can convert backwards using:

parseInt("5")
Number("5.4")
int("3")

Response to AS3 How to make text into a number 2016-08-21 00:11:52


Thanks!!!
Im new to AS3 (actionscript in general) and this is really useful!

Response to AS3 How to make text into a number 2016-08-21 18:54:36


At 8/21/16 12:11 AM, K3ter wrote: Thanks!!!
Im new to AS3 (actionscript in general) and this is really useful!

Are You Just Using Normal Actionscript no libs? Btw Wanna PM Me? I'm Quite New Myself and would love to have someone to talk to while we both work on projects..


Happy Coding

- Xploit

BBS Signature

Response to AS3 How to make text into a number 2016-08-23 11:39:47


No idea what libs are, lol.
Is that an addon?
And sure, I'll pm you.

Response to AS3 How to make text into a number 2016-08-23 13:06:27


At 8/23/16 11:39 AM, K3ter wrote: No idea what libs are, lol.

Libraries. They're essentially collections of pre-written code that make doing certain things easier.