Skip to main content
Inspiring
March 30, 2016
Question

Text fields

  • March 30, 2016
  • 1 reply
  • 348 views

I wonder how can I be creating a text field where the user may be clicking in the box and add any number to choose it.

And how can I do to set the variable will only store numeric values using a Number?

Example of text fields which I refer:

Grateful!

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
March 30, 2016

assign each textfield an instance name (in the properties panel). eg, tf_1 and tf_2.

you can use the restrict property of textfields to restrict user input to numbers.  eg,

tf_1.restrict='0-9';

and you can use the addF function to return the sum of the textfields:

function addF(tf1:TextField,tf2:TextField):Number{

if(isNaN(Number(tf1.text)) || isNaN(Number(tf2.text)){

return -1;

} else {

return Number(tf1.text)+Number(tf2.text);

}

}