user185715
user185715

Reputation:

Extending the TextInput class

Extend the TextInput Class/component to accept a "value" property as a number. I know there is a restrict method, that only allows for specified characters. The problem I am having is using a textinput to take the value in the box and apply it to math equations in a script. Any ideas?

Upvotes: 0

Views: 400

Answers (2)

Glenn
Glenn

Reputation: 5342

In addition to Amarghosh's:

You'll need to restrict something like this: "0-9\-" if you allow negatives. (yes triple-escaped...)

Also, there's the parseInt and parseFloat methods if you need specialized options like parsing from Hex.

Just make sure you check your result for NaN: isNan(result)?.

Upvotes: 0

Amarghosh
Amarghosh

Reputation: 59471

You can restrict the TextInput to 0-9. and then use its value in the script by casting it to a Number.

Math.sqrt(Number(textInput.text));

Upvotes: 1

Related Questions