Skip to main content
Inspiring
October 2, 2011
Question

Access input textfield from stage to my AS3 file

  • October 2, 2011
  • 2 replies
  • 1783 views

I have an input textfield on my stage.

I have created a AS3 Document as the Main Class for my work.

Now I need to access the user input in the textfield and work with it in my class.

What's the quickest way ?

This topic has been closed for replies.

2 replies

Ned Murphy
Legend
October 2, 2011

If the TextField is on the stage, and you are talking about your document class, then you can just target it and acquire its text property value as long as you have the TextField class imported into the class (import flash.text.TextField;).

   something = yourTextField.text;

he11f1reAuthor
Inspiring
October 2, 2011

Can it be done like this :

private var prefiksi:String = prefix.text;

"prefix" is the name of the input textfield.

It gives me an output error like this one :

TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at SwitchingHierarchy()

the 17-th line is what I wrote in beginning.

Kenneth Kawamoto
Community Expert
Community Expert
October 3, 2011

When you do this:

private var prefiksi:String = prefix.text;

"prefix" is not yet accessible because your class is not yet added to the display list. Besides if it's an input text field no point in assigning to a var like that as the input field text will change as the user inputs his/her own text into it. You'd better assign it to a var when you need to process the input text.

--

Kenneth Kawamoto

http://www.materiaprima.co.uk/

he11f1reAuthor
Inspiring
October 2, 2011

I wouldn't like to manually make input textfields with AS3...having to position them , make a max. no. of chars allowed etc etc ...Is there an easier way?