User Guide
1364 UIObject class
Description
Method; creates a TextField subobject. Used by most components to get a lightweight text
object to display text in the component while inheriting sizing and style methods and
properties of the component. This method is used to create new components. The TextField
that is created is the same as a
TextField object created using
MovieClip.createTextField(), but has the added benefit of inheriting useful properties
and methods from the parent UIObject.
A TextField that uses
UIObject.createLabel() to create within a component can take
advantage of the following inherited UIObject methods to set sizing and styles within the
context of the parent UIObject:
■ TextField.getPreferredHeight() : Number
■ TextField.getPreferredWidth() : Number
■ TextField.setStyle( styleName : String, value )
■ TextField.setSize( width : Number, height : Number)
■ TextField.setValue( text : String )
For more information, see the MultilineCell.as file example in “Simple cell renderer example”
on page 112.
Example
The following example creates a TextField instance called multiLineLabel within a
component’s
UIComponent.createChildren() method:
public function createChildren():Void {
var myTextField_txt:TextField = this.createLabel("multiLineLabel", 900,
"Hello World");
// Set the fontSize style attribute of the TextField.
myTextField_txt.setStyle("fontSize", 18);
// Set the TextField’s initial size.
myTextField_txt.setSize(myTextField_txt.getPreferredWidth(),
myTextField_txt.getPreferredHeight());
// Set the TextField’s initial location in the center of the Stage.
myTextField_txt._x = (Stage.width/2) - (myTextField_txt._width/2);
myTextField_txt._y = (Stage.height/2) - (myTextField_txt._height/2);
}
NOTE
TextFields created with UIObject.createLabel() have an initial
TextField._visible property of false. This property is used to avoid flickering
that may occur while UIObject.setSize() is called by the parent component. The
TextField._visible property is set to true when the UIObject.draw() is called
after the parent component’s children objects are resized.