| Package | starling.text |
| Class | public class TextField |
| Inheritance | TextField DisplayObjectContainer DisplayObject EventDispatcher Object |
You can set all properties you are used to, like the font name and size, a color, the horizontal and vertical alignment, etc. The border property is helpful during development, because it lets you see the bounds of the textfield.
There are two types of fonts that can be displayed:
registerBitmapFont, and then pass
the font name to the corresponding property of the text field.| Property | Defined By | ||
|---|---|---|---|
![]() | alpha : Number The opacity of the object. | DisplayObject | |
| autoScale : Boolean Indicates whether the font size is scaled down so that the complete text fits
into the text field. | TextField | ||
![]() | base : DisplayObject [read-only] The topmost object in the display tree the object is part of. | DisplayObject | |
![]() | blendMode : String The blend mode determines how the object is blended with the objects underneath. | DisplayObject | |
| bold : Boolean Indicates whether the text is bold. | TextField | ||
| border : Boolean Draws a border around the edges of the text field. | TextField | ||
![]() | bounds : Rectangle [read-only] The bounds of the object relative to the local coordinates of the parent. | DisplayObject | |
| color : uint The color of the text. | TextField | ||
![]() | filter : FragmentFilter The filter or filter group that is attached to the display object. | DisplayObject | |
| fontName : String The name of the font (true type or bitmap font). | TextField | ||
| fontSize : Number The size of the font. | TextField | ||
| hAlign : String The horizontal alignment of the text. | TextField | ||
![]() | hasVisibleArea : Boolean [read-only] Indicates if an object occupies any visible area. | DisplayObject | |
| height : Number [override] The height of the object in pixels. | TextField | ||
| italic : Boolean Indicates whether the text is italicized. | TextField | ||
| kerning : Boolean Indicates whether kerning is enabled. | TextField | ||
![]() | name : String The name of the display object (default: null). | DisplayObject | |
| nativeFilters : Array The native Flash BitmapFilters to apply to this TextField. | TextField | ||
![]() | numChildren : int [read-only] The number of children of this container. | DisplayObjectContainer | |
![]() | parent : DisplayObjectContainer [read-only] The display object container that contains this display object. | DisplayObject | |
![]() | pivotX : Number The x coordinate of the object's origin in its own coordinate space (default: 0). | DisplayObject | |
![]() | pivotY : Number The y coordinate of the object's origin in its own coordinate space (default: 0). | DisplayObject | |
![]() | root : DisplayObject [read-only] The root object the display object is connected to (i.e. | DisplayObject | |
![]() | rotation : Number The rotation of the object in radians. | DisplayObject | |
![]() | scaleX : Number The horizontal scale factor. | DisplayObject | |
![]() | scaleY : Number The vertical scale factor. | DisplayObject | |
![]() | skewX : Number The horizontal skew angle in radians. | DisplayObject | |
![]() | skewY : Number The vertical skew angle in radians. | DisplayObject | |
![]() | stage : Stage [read-only] The stage the display object is connected to, or null if it is not connected
to the stage. | DisplayObject | |
| text : String The displayed text. | TextField | ||
| textBounds : Rectangle [read-only] Returns the bounds of the text within the text field. | TextField | ||
![]() | touchable : Boolean Indicates if this object (and its children) will receive touch events. | DisplayObject | |
![]() | transformationMatrix : Matrix The transformation matrix of the object relative to its parent. | DisplayObject | |
| underline : Boolean Indicates whether the text is underlined. | TextField | ||
![]() | useHandCursor : Boolean Indicates if the mouse cursor should transform into a hand while it's over the sprite. | DisplayObject | |
| vAlign : String The vertical alignment of the text. | TextField | ||
![]() | visible : Boolean The visibility of the object. | DisplayObject | |
| width : Number [override] The width of the object in pixels. | TextField | ||
![]() | x : Number The x coordinate of the object relative to the local coordinates of the parent. | DisplayObject | |
![]() | y : Number The y coordinate of the object relative to the local coordinates of the parent. | DisplayObject | |
| Method | Defined By | ||
|---|---|---|---|
TextField(width:int, height:int, text:String, fontName:String = Verdana, fontSize:Number = 12, color:uint = 0x0, bold:Boolean = false) Create a new text field with the given properties. | TextField | ||
![]() | Adds a child to the container. | DisplayObjectContainer | |
![]() | Adds a child to the container at a certain index. | DisplayObjectContainer | |
![]() | addEventListener(type:String, listener:Function):void Registers an event listener at a certain object. | EventDispatcher | |
![]() | broadcastEvent(event:Event):void Dispatches an event on all children (recursively). | DisplayObjectContainer | |
![]() | broadcastEventWith(type:String, data:Object = null):void Dispatches an event with the given parameters on all children (recursively). | DisplayObjectContainer | |
![]() | contains(child:DisplayObject):Boolean Determines if a certain object is a child of the container (recursively). | DisplayObjectContainer | |
![]() | dispatchEvent(event:Event):void Dispatches an event to all objects that have registered listeners for its type. | EventDispatcher | |
![]() | dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void Dispatches an event with the given parameters to all objects that have registered
listeners for the given type. | EventDispatcher | |
dispose():void [override] Disposes the underlying texture data. | TextField | ||
getBitmapFont(name:String):BitmapFont [static] Returns a registered bitmap font (or null, if the font has not been registered). | TextField | ||
getBounds(targetSpace:DisplayObject, resultRect:Rectangle = null):Rectangle [override] Returns a rectangle that completely encloses the object as it appears in another
coordinate system. | TextField | ||
![]() | getChildAt(index:int):DisplayObject Returns a child object at a certain index. | DisplayObjectContainer | |
![]() | getChildByName(name:String):DisplayObject Returns a child object with a certain name (non-recursively). | DisplayObjectContainer | |
![]() | getChildIndex(child:DisplayObject):int Returns the index of a child within the container, or "-1" if it is not found. | DisplayObjectContainer | |
![]() | getTransformationMatrix(targetSpace:DisplayObject, resultMatrix:Matrix = null):Matrix Creates a matrix that represents the transformation from the local coordinate system
to another. | DisplayObject | |
![]() | globalToLocal(globalPoint:Point, resultPoint:Point = null):Point Transforms a point from global (stage) coordinates to the local coordinate system. | DisplayObject | |
![]() | hasEventListener(type:String):Boolean Returns if there are listeners registered for a certain event type. | EventDispatcher | |
![]() | hitTest(localPoint:Point, forTouch:Boolean = false):DisplayObject [override] Returns the object that is found topmost beneath a point in local coordinates, or nil if
the test fails. | DisplayObjectContainer | |
![]() | localToGlobal(localPoint:Point, resultPoint:Point = null):Point Transforms a point from the local coordinate system to global (stage) coordinates. | DisplayObject | |
registerBitmapFont(bitmapFont:BitmapFont, name:String = null):String [static] Makes a bitmap font available at any TextField in the current stage3D context. | TextField | ||
![]() | Removes a child from the container. | DisplayObjectContainer | |
![]() | removeChildAt(index:int, dispose:Boolean = false):DisplayObject Removes a child at a certain index. | DisplayObjectContainer | |
![]() | removeChildren(beginIndex:int = 0, endIndex:int = -1, dispose:Boolean = false):void Removes a range of children from the container (endIndex included). | DisplayObjectContainer | |
![]() | removeEventListener(type:String, listener:Function):void Removes an event listener from the object. | EventDispatcher | |
![]() | removeEventListeners(type:String = null):void Removes all event listeners with a certain type, or all of them if type is null. | EventDispatcher | |
![]() | removeFromParent(dispose:Boolean = false):void Removes the object from its parent, if it has one. | DisplayObject | |
render(support:RenderSupport, parentAlpha:Number):void [override] Renders the display object with the help of a support object. | TextField | ||
![]() | setChildIndex(child:DisplayObject, index:int):void Moves a child to a certain index. | DisplayObjectContainer | |
![]() | sortChildren(compareFunction:Function):void Sorts the children according to a given function (that works just like the sort function
of the Vector class). | DisplayObjectContainer | |
![]() | Swaps the indexes of two children. | DisplayObjectContainer | |
![]() | swapChildrenAt(index1:int, index2:int):void Swaps the indexes of two children. | DisplayObjectContainer | |
unregisterBitmapFont(name:String, dispose:Boolean = true):void [static] Unregisters the bitmap font and, optionally, disposes it. | TextField | ||
| autoScale | property |
autoScale:BooleanIndicates whether the font size is scaled down so that the complete text fits into the text field.
The default value is false.
public function get autoScale():Boolean public function set autoScale(value:Boolean):void| bold | property |
bold:BooleanIndicates whether the text is bold.
The default value is false.
public function get bold():Boolean public function set bold(value:Boolean):void| border | property |
border:BooleanDraws a border around the edges of the text field. Useful for visual debugging.
The default value is false.
public function get border():Boolean public function set border(value:Boolean):void| color | property |
color:uint The color of the text. For bitmap fonts, use Color.WHITE to use the
original, untinted color.
The default value is black.
public function get color():uint public function set color(value:uint):void| fontName | property |
fontName:StringThe name of the font (true type or bitmap font).
public function get fontName():String public function set fontName(value:String):void| fontSize | property |
fontSize:Number The size of the font. For bitmap fonts, use BitmapFont.NATIVE_SIZE for
the original size.
public function get fontSize():Number public function set fontSize(value:Number):void| hAlign | property |
hAlign:StringThe horizontal alignment of the text.
The default value is center.
public function get hAlign():String public function set hAlign(value:String):voidSee also
| height | property |
height:Number[override] The height of the object in pixels.
public function get height():Number public function set height(value:Number):void| italic | property |
italic:BooleanIndicates whether the text is italicized.
The default value is false.
public function get italic():Boolean public function set italic(value:Boolean):void| kerning | property |
kerning:BooleanIndicates whether kerning is enabled.
The default value is true.
public function get kerning():Boolean public function set kerning(value:Boolean):void| nativeFilters | property |
nativeFilters:ArrayThe native Flash BitmapFilters to apply to this TextField. Only available when using standard (TrueType) fonts!
public function get nativeFilters():Array public function set nativeFilters(value:Array):void| text | property |
text:StringThe displayed text.
public function get text():String public function set text(value:String):void| textBounds | property |
textBounds:Rectangle [read-only] Returns the bounds of the text within the text field.
public function get textBounds():Rectangle| underline | property |
underline:BooleanIndicates whether the text is underlined.
The default value is false.
public function get underline():Boolean public function set underline(value:Boolean):void| vAlign | property |
vAlign:StringThe vertical alignment of the text.
The default value is center.
public function get vAlign():String public function set vAlign(value:String):voidSee also
| width | property |
width:Number[override] The width of the object in pixels.
public function get width():Number public function set width(value:Number):void| TextField | () | Constructor |
public function TextField(width:int, height:int, text:String, fontName:String = Verdana, fontSize:Number = 12, color:uint = 0x0, bold:Boolean = false)Create a new text field with the given properties.
Parameterswidth:int | |
height:int | |
text:String | |
fontName:String (default = Verdana) | |
fontSize:Number (default = 12) | |
color:uint (default = 0x0) | |
bold:Boolean (default = false) |
| dispose | () | method |
override public function dispose():voidDisposes the underlying texture data.
| getBitmapFont | () | method |
public static function getBitmapFont(name:String):BitmapFontReturns a registered bitmap font (or null, if the font has not been registered).
Parameters
name:String |
BitmapFont |
| getBounds | () | method |
override public function getBounds(targetSpace:DisplayObject, resultRect:Rectangle = null):RectangleReturns a rectangle that completely encloses the object as it appears in another coordinate system. If you pass a 'resultRectangle', the result will be stored in this rectangle instead of creating a new object.
Parameters
targetSpace:DisplayObject | |
resultRect:Rectangle (default = null) |
Rectangle |
| registerBitmapFont | () | method |
public static function registerBitmapFont(bitmapFont:BitmapFont, name:String = null):String Makes a bitmap font available at any TextField in the current stage3D context.
The font is identified by its name.
Per default, the name property of the bitmap font will be used, but you
can pass a custom name, as well.
Parameters
bitmapFont:BitmapFont | |
name:String (default = null) |
String |
| render | () | method |
override public function render(support:RenderSupport, parentAlpha:Number):voidRenders the display object with the help of a support object. Never call this method directly, except from within another render method.
Parameters
support:RenderSupport — Provides utility functions for rendering.
| |
parentAlpha:Number — The accumulated alpha value from the object's parent up to the stage. |
| unregisterBitmapFont | () | method |
public static function unregisterBitmapFont(name:String, dispose:Boolean = true):voidUnregisters the bitmap font and, optionally, disposes it.
Parameters
name:String | |
dispose:Boolean (default = true) |