PDA

View Full Version : Access TextField that is a member of a class



bortiquai
March 20th, 2009, 08:20 PM
I have created a class, that is simply a group of text fields. In the main app, I create instances of this class, and add them to the main app.

How can i access the textFields that are in the class, to say, change the text, etc...

jackcviers
March 20th, 2009, 09:33 PM
I have created a class, that is simply a group of text fields. In the main app, I create instances of this class, and add them to the main app.

How can i access the textFields that are in the class, to say, change the text, etc...

1. mark them as public in the class.
2. mark them as private and provide getter methods for them in the class that return the references to the textfields.

then instantiate your class and : myClassInstance.myNamedTextField.text = "Hello World";

You have access to them. Those are the easiest ways.

jwerre
March 20th, 2009, 09:41 PM
private var _myText:TextField;

public function get myText():TextField
{
return _myText;
}

public function set myText(value:TextField):void
{
if (value !== _myText)
{
_myText = value;
}
}



and then in the other class you can do something like


MyTextClass.myText.text = "foo bar"

bortiquai
March 20th, 2009, 09:41 PM
Number 1 I get.

Can you breifely tell me what a getter method is?

Which method (if either) is better?

Thanks for the help