| Package | flash.text |
| Class | public class TextField |
| Inheritance | TextField InteractiveObject DisplayObject EventDispatcher Object |
| Subclasses | FlexTextField |
To create a text field dynamically, use the TextField() constructor.
The methods of the TextField class let you set, select, and manipulate text in a dynamic or input text field that you create during authoring or at runtime.
ActionScript provides several ways to
format your text at runtime. The TextFormat class lets you set character and paragraph formatting
for TextField objects. You can apply Cascading Style Sheets (CSS) styles
to text fields by using the TextField.styleSheet property and the StyleSheet class. You can use CSS to
style built-in HTML tags, define new formatting tags, or apply styles.
You can assign HTML formatted text, which might optionally use CSS styles, directly to a text
field. HTML text that you assign to a text field can contain embedded
media (movie clips, SWF files, GIF files, PNG files, and JPEG files). The text wraps around the
embedded media in the same way that a web browser wraps text around media embedded in an HTML document.
Flash Player supports a subset of HTML tags that you can use to format text. See the list of supported HTML tags in the description of the htmlText property.
See also
| Property | Defined by | ||
|---|---|---|---|
![]() | accessibilityProperties : AccessibilityProperties
The current accessibility options for this display object.
| DisplayObject | |
![]() | alpha : Number
Indicates the alpha transparency value of the object specified.
| DisplayObject | |
| alwaysShowSelection : Boolean
When set to
true and the text field is not in focus, Flash Player highlights the
selection in the text field in gray. | TextField | ||
| antiAliasType : String
The type of anti-aliasing used for this text field.
| TextField | ||
| autoSize : String
Controls automatic sizing and alignment of text fields.
| TextField | ||
| background : Boolean
Specifies whether the text field has a background fill.
| TextField | ||
| backgroundColor : uint
The color of the text field background.
| TextField | ||
![]() | blendMode : String
A value from the BlendMode class that specifies which blend mode to use.
| DisplayObject | |
| border : Boolean
Specifies whether the text field has a border.
| TextField | ||
| borderColor : uint
The color of the text field border.
| TextField | ||
| bottomScrollV : int
[read-only]
An integer (1-based index) that indicates the bottommost line that is currently visible in
the specified text field.
| TextField | ||
![]() | cacheAsBitmap : Boolean
If set to
true, Flash Player caches an internal bitmap representation of the
display object. | DisplayObject | |
| caretIndex : int
[read-only]
The index of the insertion point (caret) position.
| TextField | ||
| condenseWhite : Boolean
A Boolean value that specifies whether extra white space (spaces, line breaks, and so on)
in a text field with HTML text should be removed.
| TextField | ||
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
![]() | contextMenu : ContextMenu
Specifies the context menu associated with this object.
| InteractiveObject | |
| defaultTextFormat : TextFormat
Specifies the format applied to newly inserted text, such as text inserted with the
replaceSelectedText() method or text entered by a user. | TextField | ||
| displayAsPassword : Boolean
Specifies whether the text field is a password text field.
| TextField | ||
![]() | doubleClickEnabled : Boolean
Specifies whether the object receives
doubleClick events. | InteractiveObject | |
| embedFonts : Boolean
Specifies whether to render by using embedded font outlines.
| TextField | ||
![]() | filters : Array
An indexed array that contains each filter object currently associated with the display object.
| DisplayObject | |
![]() | focusRect : Object
Specifies whether this object displays a focus rectangle.
| InteractiveObject | |
| gridFitType : String
The type of grid fitting used for this text field.
| TextField | ||
![]() | height : Number
Indicates the height of the display object, in pixels.
| DisplayObject | |
| htmlText : String
Contains the HTML representation of the text field's contents.
| TextField | ||
| length : int
[read-only]
The number of characters in a text field.
| TextField | ||
![]() | loaderInfo : LoaderInfo
Returns a LoaderInfo object containing information about loading the file
to which this display object belongs.
| DisplayObject | |
![]() | mask : DisplayObject
The calling display object is masked by the specified
mask object. | DisplayObject | |
| maxChars : int
The maximum number of characters that the text field can contain, as entered by a user.
| TextField | ||
| maxScrollH : int
[read-only]
The maximum value of
scrollH. | TextField | ||
| maxScrollV : int
[read-only]
The maximum value of
scrollV. | TextField | ||
![]() | mouseEnabled : Boolean
Specifies whether this object receives mouse messages.
| InteractiveObject | |
| mouseWheelEnabled : Boolean
A Boolean value that indicates whether Flash Player should automatically scroll multiline
text fields when the user clicks a text field and rolls the mouse wheel.
| TextField | ||
![]() | mouseX : Number
Indicates the x coordinate of the mouse position, in pixels.
| DisplayObject | |
![]() | mouseY : Number
Indicates the y coordinate of the mouse position, in pixels.
| DisplayObject | |
| multiline : Boolean
Indicates whether the text field is a multiline text field.
| TextField | ||
![]() | name : String
Indicates the instance name of the DisplayObject.
| DisplayObject | |
| numLines : int
[read-only]
Defines the number of text lines in a multiline text field.
| TextField | ||
![]() | opaqueBackground : Object
Specifies whether the display object is opaque with a certain background color.
| DisplayObject | |
![]() | parent : DisplayObjectContainer
Indicates the DisplayObjectContainer object that contains this display object.
| DisplayObject | |
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| restrict : String
Indicates the set of characters that a user can enter into the text field.
| TextField | ||
![]() | root : DisplayObject
For a display object in a loaded SWF file, the
root property is the
top-most display object in the portion of the display list's tree structure represented by that SWF file. | DisplayObject | |
![]() | rotation : Number
Indicates the rotation of the DisplayObject instance, in degrees, from its original orientation.
| DisplayObject | |
![]() | scale9Grid : Rectangle
The current scaling grid that is in effect.
| DisplayObject | |
![]() | scaleX : Number
Indicates the horizontal scale (
percentage) of the object as applied from the registration point. | DisplayObject | |
![]() | scaleY : Number
Indicates the vertical scale (
percentage) of an object as applied from the registration point of the object. | DisplayObject | |
| scrollH : int
The current horizontal scrolling position.
| TextField | ||
![]() | scrollRect : Rectangle
The scroll rectangle bounds of the display object.
| DisplayObject | |
| scrollV : int
The vertical position of text in a text field.
| TextField | ||
| selectable : Boolean
A Boolean value that indicates whether the text field is selectable.
| TextField | ||
| selectionBeginIndex : int
[read-only]
The zero-based character index value of the first character in the current selection.
| TextField | ||
| selectionEndIndex : int
[read-only]
The zero-based character index value of the last character in the current selection.
| TextField | ||
| sharpness : Number
The sharpness of the glyph edges in this text field.
| TextField | ||
![]() | stage : Stage
The Stage of the display object.
| DisplayObject | |
| styleSheet : StyleSheet
Attaches a style sheet to the text field.
| TextField | ||
![]() | tabEnabled : Boolean
Specifies whether this object is in the tab order.
| InteractiveObject | |
![]() | tabIndex : int
Specifies the tab ordering of objects in a SWF file.
| InteractiveObject | |
| text : String
A string that is the current text in the text field.
| TextField | ||
| textColor : uint
The color of the text in a text field, in hexadecimal format.
| TextField | ||
| textHeight : Number
[read-only]
The height of the text in pixels.
| TextField | ||
| textWidth : Number
[read-only]
The width of the text in pixels.
| TextField | ||
| thickness : Number
The thickness of the glyph edges in this text field.
| TextField | ||
![]() | transform : Transform
An object with properties pertaining to a display object's matrix, color transform, and pixel bounds.
| DisplayObject | |
| type : String
The type of the text field.
| TextField | ||
| useRichTextClipboard : Boolean
Specifies whether to copy and paste the text formatting along with the text.
| TextField | ||
![]() | visible : Boolean
Whether or not the display object is visible.
| DisplayObject | |
![]() | width : Number
Indicates the width of the display object, in pixels.
| DisplayObject | |
| wordWrap : Boolean
A Boolean value that indicates whether the text field has word wrap.
| TextField | ||
![]() | x : Number
Indicates the x coordinate of the DisplayObject instance relative to the local coordinates of
the parent DisplayObjectContainer.
| DisplayObject | |
![]() | y : Number
Indicates the y coordinate of the DisplayObject instance relative to the local coordinates of
the parent DisplayObjectContainer.
| DisplayObject | |
| Method | Defined by | ||
|---|---|---|---|
|
Creates a new TextField instance.
| TextField | ||
![]() |
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event.
| EventDispatcher | |
|
Appends the string specified by the
newText parameter to the end of the text
of the text field. | TextField | ||
![]() |
Dispatches an event into the event flow.
| EventDispatcher | |
![]() |
Returns a rectangle that defines the area of the display object relative to the coordinate system
of the
targetCoordinateSpace object. | DisplayObject | |
|
Returns a rectangle that is the bounding box of the character.
| TextField | ||
|
Returns the zero-based index value of the character at the point specified by the
x
and y parameters. | TextField | ||
|
Given a character index, returns the index of the first character in the same paragraph.
| TextField | ||
|
Returns a DisplayObject reference for the given
id, for an image or SWF file
that has been added to an HTML-formatted text field by using an <img> tag. | TextField | ||
|
Returns the zero-based index value of the line at the point specified by the
x
and y parameters. | TextField | ||
|
Returns the zero-based index value of the line containing the character specified
by the
charIndex parameter. | TextField | ||
|
Returns the number of characters in a specific text line.
| TextField | ||
|
Returns metrics information about a given text line.
| TextField | ||
|
Returns the character index of the first character in the line that
the
lineIndex parameter specifies. | TextField | ||
|
Returns the text of the line specified by the
lineIndex parameter. | TextField | ||
|
Given a character index, returns the length of the paragraph containing the given character.
| TextField | ||
![]() |
Returns a rectangle that defines the boundary of the display object,
based on the coordinate system defined by the
targetCoordinateSpace
parameter, excluding any strokes on shapes. | DisplayObject | |
|
Returns a TextFormat object that contains formatting information for the range of text that the
beginIndex and endIndex parameters specify. | TextField | ||
![]() |
Converts the
point object from the Stage (global) coordinates
to the display object's (local) coordinates. | DisplayObject | |
![]() |
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event.
| EventDispatcher | |
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Evaluates the display object to see if it overlaps or intersects with the
obj display object. | DisplayObject | |
![]() |
Evaluates the display object to see if it overlaps or intersects with the
point specified by the
x and y parameters. | DisplayObject | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Converts the
point object from the display object's (local) coordinates to the
Stage (global) coordinates. | DisplayObject | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Removes a listener from the EventDispatcher object.
| EventDispatcher | |
|
Replaces the current selection with the contents of the
value parameter. | TextField | ||
|
Replaces the range of characters that the
beginIndex and
endIndex parameters specify with the contents
of the newText parameter. | TextField | ||
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
Sets as selected the text designated by the index values of the
first and last characters, which are specified with the
beginIndex
and endIndex parameters. | TextField | ||
|
Applies the text formatting that the
format parameter specifies to the specified text in a text field. | TextField | ||
![]() |
Returns the string representation of the specified object.
| Object | |
![]() |
Returns the primitive value of the specified object.
| Object | |
![]() |
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type.
| EventDispatcher | |
| Event | Summary | Defined by | ||
|---|---|---|---|---|
![]() | Dispatched when Flash Player gains operating system focus and becomes active. | EventDispatcher | ||
![]() | Dispatched when a display object is added to the display list. | DisplayObject | ||
![]() | Dispatched when a display object is added to the on stage display list, either directly or through the addition of a sub tree in which the display object is contained. | DisplayObject | ||
| Dispatched after a control's value is modified. | TextField | |||
![]() | Dispatched when a user presses and releases the main button of the user's pointing device over the same InteractiveObject. | InteractiveObject | ||
![]() | Dispatched when Flash Player loses operating system focus and is becoming inactive. | EventDispatcher | ||
![]() |
Dispatched when a user presses and releases the main button of a pointing device twice in
rapid succession over the same InteractiveObject when that object's
doubleClickEnabled flag is set to true. | InteractiveObject | ||
![]() | Dispatched when the playhead is entering a new frame. | DisplayObject | ||
![]() | Dispatched after a display object gains focus. | InteractiveObject | ||
![]() | Dispatched after a display object loses focus. | InteractiveObject | ||
![]() | Dispatched when the user presses a key. | InteractiveObject | ||
![]() | Dispatched when the user attempts to change focus by using keyboard navigation. | InteractiveObject | ||
![]() | Dispatched when the user releases a key. | InteractiveObject | ||
| Dispatched when a user clicks a hyperlink in an HTML-enabled text field, where the URL begins with "event:". | TextField | |||
![]() | Dispatched when a user presses the pointing device button over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when the user attempts to change focus by using a pointer device. | InteractiveObject | ||
![]() | Dispatched when a user moves the pointing device while it is over an InteractiveObject. | InteractiveObject | ||
![]() | Dispatched when the user moves a pointing device away from an InteractiveObject instance. | InteractiveObject | ||
![]() | Dispatched when the user moves a pointing device over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when a user releases the pointing device button over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when a mouse wheel is spun over an InteractiveObject instance in the Flash Player window. | InteractiveObject | ||
![]() | Dispatched when a display object is about to be removed from the display list. | DisplayObject | ||
![]() | Dispatched when a display object is about to be removed from the display list, either directly or through the removal of a sub tree in which the display object is contained. | DisplayObject | ||
![]() | Dispatched when the display list is about to be updated and rendered. | DisplayObject | ||
![]() | Dispatched when the user moves a pointing device away from an InteractiveObject instance. | InteractiveObject | ||
![]() | Dispatched when the user moves a pointing device over an InteractiveObject instance. | InteractiveObject | ||
| Dispatched by a TextField object after the user scrolls. | TextField | |||
![]() |
Dispatched when the value of the object's tabChildren flag changes. | InteractiveObject | ||
![]() |
Dispatched when the object's tabEnabled flag changes. | InteractiveObject | ||
![]() |
Dispatched when the value of the object's tabIndex property changes. | InteractiveObject | ||
Flash Player dispatches the textInput event when a user enters one or more
characters of text. | TextField | |||
| alwaysShowSelection | property |
alwaysShowSelection:Boolean [read-write]
When set to true and the text field is not in focus, Flash Player highlights the
selection in the text field in gray. When set to false and the text field is not in
focus, Flash Player does not highlight the selection in the text field.
The default value is false.
public function get alwaysShowSelection():Boolean
public function set alwaysShowSelection(value:Boolean):void
See also
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_alwaysShowSelection extends Sprite {
public function TextField_alwaysShowSelection() {
var label1:TextField = createTextField(0, 20, 200, 20);
label1.text = "This text is selected.";
label1.setSelection(0, 9);
label1.alwaysShowSelection = true;
var label2:TextField = createTextField(0, 50, 200, 20);
label2.text = "Drag to select some of this text.";
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x; result.y = y;
result.width = width; result.height = height;
addChild(result);
return result;
}
}
}
| antiAliasType | property |
antiAliasType:String [read-write]
The type of anti-aliasing used for this text field. Use flash.text.AntiAliasType
constants for this property. You can control this setting only if the font is
embedded (with the embedFonts property set to true).
The default setting is flash.text.AntiAliasType.ADVANCED.
To set values for this property, use the following string values:
| String value | Description |
|---|---|
flash.text.AntiAliasType.NORMAL |
Applies the regular text anti-aliasing. This matches the type of anti-aliasing that Flash Player 7 and earlier versions used. |
flash.text.AntiAliasType.ADVANCED |
Applies advanced anti-aliasing, which makes text more legible. (This feature became available in Flash Player 8.) Advanced anti-aliasing allows for high-quality rendering of font faces at small sizes. It is best used with applications that have a lot of small text. Advanced anti-aliasing is not recommended for fonts that are larger than 48 points. |
public function get antiAliasType():String
public function set antiAliasType(value:String):void
See also
| autoSize | property |
autoSize:String [read-write]
Controls automatic sizing and alignment of text fields.
Acceptable values for the TextFieldAutoSize constants: TextFieldAutoSize.NONE (the default),
TextFieldAutoSize.LEFT, TextFieldAutoSize.RIGHT, and TextFieldAutoSize.CENTER.
If autoSize is set to TextFieldAutoSize.NONE (the default) no resizing occurs.
If autoSize is set to TextFieldAutoSize.LEFT, the text is
treated as left-justified text, meaning that the left margin of the text field remains fixed and any
resizing of a single line of the text field is on the right margin. If the text includes a line break
(for example, "\n" or "\r"), the bottom is also resized to fit the next
line of text. If wordWrap is also set to true, only the bottom
of the text field is resized and the right side remains fixed.
If autoSize is set to TextFieldAutoSize.RIGHT, the text is treated as
right-justified text, meaning that the right margin of the text field remains fixed and any resizing
of a single line of the text field is on the left margin. If the text includes a line break
(for example, "\n" or "\r"), the bottom is also resized to fit the next
line of text. If wordWrap is also set to true, only the bottom
of the text field is resized and the left side remains fixed.
If autoSize is set to TextFieldAutoSize.CENTER, the text is treated as
center-justified text, meaning that any resizing of a single line of the text field is equally distributed
to both the right and left margins. If the text includes a line break (for example, "\n" or
"\r"), the bottom is also resized to fit the next line of text. If wordWrap is also
set to true, only the bottom of the text field is resized and the left and
right sides remain fixed.
public function get autoSize():String
public function set autoSize(value:String):void
ArgumentError — The autoSize specified is not a member of flash.text.TextFieldAutoSize.
|
See also
| background | property |
background:Boolean [read-write]
Specifies whether the text field has a background fill. If true, the text field has a
background fill. If false, the text field has no background fill.
Use the backgroundColor property to set the background color of a text field.
The default value is false.
public function get background():Boolean
public function set background(value:Boolean):void
See also
| backgroundColor | property |
backgroundColor:uint [read-write]
The color of the text field background. The default value is 0xFFFFFF (white).
This property can be retrieved or set, even if there currently is no background, but the
color is visible only if the text field has the background property set to
true.
public function get backgroundColor():uint
public function set backgroundColor(value:uint):void
See also
| border | property |
border:Boolean [read-write]
Specifies whether the text field has a border. If true, the text field has a border.
If false, the text field has no border. Use the borderColor property
to set the border color.
The default value is false.
public function get border():Boolean
public function set border(value:Boolean):void
See also
| borderColor | property |
borderColor:uint [read-write]
The color of the text field border. The default value is 0x000000 (black).
This property can be retrieved or set, even if there currently is no border, but the
color is visible only if the text field has the border property set to
true.
public function get borderColor():uint
public function set borderColor(value:uint):void
See also
| bottomScrollV | property |
bottomScrollV:int [read-only]
An integer (1-based index) that indicates the bottommost line that is currently visible in
the specified text field. Think of the text field as a window onto a block of text.
The scrollV property is the 1-based index of the topmost visible line
in the window.
All the text between the lines indicated by scrollV and bottomScrollV
is currently visible in the text field.
public function get bottomScrollV():int
See also
| caretIndex | property |
caretIndex:int [read-only]The index of the insertion point (caret) position. If no insertion point is displayed, the value is the position the insertion point would be if you restored focus to the field (typically where the insertion point last was, or 0 if the field has not had focus).
Selection span indexes are zero-based (for example, the first position is 0, the second position is 1, and so on).
Implementation public function get caretIndex():int
See also
printCursorPosition method is called. In that case, the values of the
caretIndex, selectionBeginIndex, and
selectionEndIndex properties are output.
Run this example and try clicking in the TextField to select text. Then click in the field without
selecting text. When you click in the text without making a selection, the
caretIndex property indicates where the insertion point occurs, and the selectionBeginIndex
and selectionEndIndex properties equal the caretIndex property value.
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_caretIndex extends Sprite {
public function TextField_caretIndex() {
var tf:TextField = createTextField(10, 10, 100, 100);
tf.wordWrap = true;
tf.type = TextFieldType.INPUT;
tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
}
private function printCursorPosition(event:MouseEvent):void {
var tf:TextField = TextField(event.target);
trace("caretIndex:", tf.caretIndex);
trace("selectionBeginIndex:", tf.selectionBeginIndex);
trace("selectionEndIndex:", tf.selectionEndIndex);
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
addChild(result);
return result;
}
}
}
| condenseWhite | property |
condenseWhite:Boolean [read-write]
A Boolean value that specifies whether extra white space (spaces, line breaks, and so on)
in a text field with HTML text should be removed. The default value is false.
The condenseWhite property only affects text set with
the htmlText property, not the text property. If you set
text with the text property, condenseWhite is ignored.
If you set condenseWhite to true, you must use standard HTML commands such as
<BR> and <P> to place line breaks in the text field.
Set the condenseWhite property before setting the htmlText property.
public function get condenseWhite():Boolean
public function set condenseWhite(value:Boolean):void
See also
condenseWhite
setting to false and setting it to true:
package {
import flash.display.Sprite;
import flash.text.TextField;
public class TextField_condenseWhite extends Sprite {
public function TextField_condenseWhite() {
var tf1:TextField = createTextField(0, 0, 200, 50);
tf1.condenseWhite = false;
tf1.htmlText = "keep on\n\ttruckin'";
var tf2:TextField = createTextField(0, 120, 200, 50);
tf2.condenseWhite = true;
tf2.htmlText = "keep on\n\ttruckin'";
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
result.border = true;
addChild(result);
return result;
}
}
}
| defaultTextFormat | property |
defaultTextFormat:TextFormat [read-write]
Specifies the format applied to newly inserted text, such as text inserted with the
replaceSelectedText() method or text entered by a user.
When you access the defaultTextFormat property, the returned TextFormat object has all
of its properties defined. No property is null.
Note: You can't set this property if a style sheet is applied to the text field.
Implementation public function get defaultTextFormat():TextFormat
public function set defaultTextFormat(value:TextFormat):void
Error — This method cannot be used on a text field with a style sheet.
|
See also
| displayAsPassword | property |
displayAsPassword:Boolean [read-write]
Specifies whether the text field is a password text field. If the value of this property is true,
the text field is treated as a password text field and hides the input characters using asterisks instead of the
actual characters. If false, the text field is not treated as a password text field. When password mode
is enabled, the Cut and Copy commands and their corresponding keyboard shortcuts will
not function. This security mechanism prevents an unscrupulous user from using the shortcuts to discover
a password on an unattended computer.
The default value is false.
public function get displayAsPassword():Boolean
public function set displayAsPassword(value:Boolean):void
| embedFonts | property |
embedFonts:Boolean [read-write]
Specifies whether to render by using embedded font outlines.
If false, Flash Player renders the text field by using
device fonts.
If you set the embedFonts property to true for a text field,
you must specify a font for that text by using the font property of
a TextFormat object applied to the text field.
If the specified font is not embedded in the SWF file, the text is not displayed.
The default value is false.
public function get embedFonts():Boolean
public function set embedFonts(value:Boolean):void
See also
| gridFitType | property |
gridFitType:String [read-write]
The type of grid fitting used for this text field. This property applies only if the
flash.text.AntiAliasType property of the text field is set to flash.text.AntiAliasType.ADVANCED.
The type of grid fitting used determines whether Flash Player forces strong horizontal and vertical lines to fit to a pixel or subpixel grid, or not at all.
For the flash.text.GridFitType property, you can use the following string values:
| String value | Description |
|---|---|
flash.text.GridFitType.NONE |
Specifies no grid fitting. Horizontal and vertical lines in the glyphs are not forced to the pixel grid. This setting is usually good for animation or for large font sizes. |
flash.text.GridFitType.PIXEL |
Specifies that strong horizontal and vertical lines are fit to the
pixel grid. This setting works only for left-aligned text fields.
To use this setting, the flash.dispaly.AntiAliasType property of the text field
must be set to flash.text.AntiAliasType.ADVANCED.
This setting generally provides the best legibility for
left-aligned text. |
flash.text.GridFitType.SUBPIXEL |
Specifies that strong horizontal and vertical lines are fit to the subpixel grid on
an LCD monitor. To use this setting, the
flash.text.AntiAliasType property of the text field must be set to
flash.text.AntiAliasType.ADVANCED. The flash.text.GridFitType.SUBPIXEL setting is often good
for right-aligned or centered
dynamic text, and it is sometimes a useful trade-off for animation versus text quality. |
The default value is pixel.
public function get gridFitType():String
public function set gridFitType(value:String):void
See also
| htmlText | property |
htmlText:String [read-write]Contains the HTML representation of the text field's contents.
Flash Player supports the following HTML tags:
| Tag | Description |
|---|---|
| Anchor tag |
The <a> tag creates a hypertext link and supports the following attributes:
You can use the link event to cause the link to execute an ActionScript function in a SWF file instead of opening a URL. You can also define |
| Bold tag |
The <b> tag renders text as bold. A bold typeface must be available for the font used.
|
| Break tag |
The <br> tag creates a line break in the text field. You must set the text field to
be a multiline text field to use this tag.
|
| Font tag |
The <font> tag specifies a font or list of fonts to display the text.The font tag
supports the following attributes:
|
| Image tag |
The <img> tag lets you embed external image files (JPEG, GIF, PNG), SWF files, and
movie clips inside text fields. Text automatically flows around images you embed in text fields. To use
this tag, you must set the text field to be multiline and to wrap text.
The
Flash displays media embedded in a text field at full size. To specify the dimensions of the media
you are embedding, use the In general, an image embedded in a text field appears on the line following the
|
| Italic tag |
The <i> tag displays the tagged text in italics. An italic typeface must be available
for the font used.
|
| List item tag |
The <li> tag places a bullet in front of the text that it encloses.
Note: Because Flash Player does not recognize ordered and unordered list tags (<ol>
and <ul>, they do not modify how your list is rendered. All lists are unordered and all
list items use bullets.
|
| Paragraph tag |
The <p> tag creates a new paragraph. You must set the text field to be a multiline
text field to use this tag.
The <p> tag supports the following attributes:
|
| Span tag |
The <span> tag is available only for use with CSS text styles. It supports the
following attribute:
|
| Text format tag |
The The
|
| Underline tag |
The <u> tag underlines the tagged text.
|
Flash Player supports the following HTML entities:
| Entity | Description |
|---|---|
| < | < (less than) |
| > | > (greater than) |
| & | & (ampersand) |
| " | " (double quotes) |
| ' | ' (apostrophe, single quote) |
Flash also supports explicit character codes, such as & (ASCII ampersand) and € (Unicode € symbol).
Implementation public function get htmlText():String
public function set htmlText(value:String):void
See also
tf1, and assigns an
HTML-formatted String to its text property. When its htmlText property
is traced, the output is the HTML-formatted String, with additional tags (such as <P> and
<FONT>) automatically added by Flash Player. When the value of the text
property is traced, the unformatted string without HTML tags is displayed.
By way of comparison, the same steps are performed on another TextField object named
tf2, with the addition that a StyleSheet object is assigned to tf2's
styleSheet property before its htmlText property is set. In that case,
when the htmlText property is traced, it only includes the exact HTML text that was
originally assigned to the htmlText property, showing that no additional tags were
added by Flash Player.
package {
import flash.display.Sprite;
import flash.text.StyleSheet;
import flash.text.TextField;
public class TextField_text extends Sprite {
public function TextField_text() {
var tf1:TextField = createTextField(10, 10, 400, 22);
tf1.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";
// htmlText: <P ALIGN="LEFT"><FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0"><b>Lorem ipsum dolor sit amet.</b></FONT></P>
trace("htmlText: " + tf1.htmlText);
// text: Lorem ipsum dolor sit amet.
trace("text: " + tf1.text);
var tf2:TextField = createTextField(10, 50, 400, 22);
tf2.styleSheet = new StyleSheet();
tf2.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";
// htmlText: <b>Lorem ipsum dolor sit amet.</b>
trace("htmlText: " + tf2.htmlText);
// text: Lorem ipsum dolor sit amet.
trace("text: " + tf2.text);
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
addChild(result);
return result;
}
}
}
| length | property |
length:int [read-only]
The number of characters in a text field. A character such as tab (\t) counts as one
character.
public function get length():int
| maxChars | property |
maxChars:int [read-write]
The maximum number of characters that the text field can contain, as entered by a user.
A script can insert more text than maxChars allows; the maxChars property
indicates only how much text a user can enter. If the value of this property is 0,
a user can enter an unlimited amount of text.
The default value is 0.
public function get maxChars():int
public function set maxChars(value:int):void
| maxScrollH | property |
maxScrollH:int [read-only]
The maximum value of scrollH.
public function get maxScrollH():int
See also
| maxScrollV | property |
maxScrollV:int [read-only]
The maximum value of scrollV.
public function get maxScrollV():int
See also
| mouseWheelEnabled | property |
mouseWheelEnabled:Boolean [read-write]
A Boolean value that indicates whether Flash Player should automatically scroll multiline
text fields when the user clicks a text field and rolls the mouse wheel.
By default, this value is true. This property is useful if you want to prevent
mouse wheel scrolling of text fields, or implement your own text field scrolling.
public function get mouseWheelEnabled():Boolean
public function set mouseWheelEnabled(value:Boolean):void
| multiline | property |
multiline:Boolean [read-write]
Indicates whether the text field is a multiline text field. If the value is true,
the text field is multiline; if the value is false, the text field is a single-line
text field.
The default value is false.
public function get multiline():Boolean
public function set multiline(value:Boolean):void
See also
| numLines | property |
numLines:int [read-only]
Defines the number of text lines in a multiline text field.
If wordWrap property is set to true,
the number of lines increases when text wraps.
public function get numLines():int
See also
| restrict | property |
restrict:String [read-write]
Indicates the set of characters that a user can enter into the text field. If the value of the
restrict property is null, you can enter any character. If the value of
the restrict property is an empty string, you cannot enter any character. If the value
of the restrict property is a string of characters, you can enter only characters in
the string into the text field. The string is scanned from left to right. You can specify a range by
using the hyphen (-) character. This only restricts user interaction; a script may put any text into the
text field. This property does not synchronize with the Embed font options
in the Property inspector.
If the string begins with a caret (^) character, all characters are initially accepted and succeeding characters in the string are excluded from the set of accepted characters. If the string does not begin with a caret (^) character, no characters are initially accepted and succeeding characters in the string are included in the set of accepted characters.
The following example allows only uppercase characters, spaces, and numbers to be entered into a text field:
my_txt.restrict = "A-Z 0-9";
The following example includes all characters, but excludes lowercase letters:
my_txt.restrict = "^a-z";
You can use a backslash to enter a ^ or - verbatim. The accepted backslash sequences are \-, \^ or \\. The backslash must be an actual character in the string, so when specified in ActionScript, a double backslash must be used. For example, the following code includes only the dash (-) and caret (^):
my_txt.restrict = "\\-\\^";
The ^ may be used anywhere in the string to toggle between including characters and excluding characters. The following code includes only uppercase letters, but excludes the uppercase letter Q:
my_txt.restrict = "A-Z^Q";
You can use the u escape sequence to construct restrict strings.
The following code includes only the characters from ASCII 32 (space) to ASCII 126 (tilde).
my_txt.restrict = " -~";
The default value is null.
public function get restrict():String
public function set restrict(value:String):void
| scrollH | property |
scrollH:int [read-write]
The current horizontal scrolling position. If the scrollH property is 0, the text
is not horizontally scrolled. This property value is an integer that represents the horizontal
position in pixels.
The units of horizontal scrolling are pixels, whereas the units of vertical scrolling are lines. Horizontal scrolling is measured in pixels because most fonts you typically use are proportionally spaced; that is, the characters can have different widths. Flash Player performs vertical scrolling by line because users usually want to see a complete line of text rather than a partial line. Even if a line uses multiple fonts, the height of the line adjusts to fit the largest font in use.
Note: The scrollH property is zero-based, not 1-based like
the scrollV vertical scrolling property.
public function get scrollH():int
public function set scrollH(value:int):void
See also
| scrollV | property |
scrollV:int [read-write]
The vertical position of text in a text field. The scrollV property is useful for
directing users to a specific paragraph in a long passage, or creating scrolling text fields.
The units of vertical scrolling are lines, whereas the units of horizontal scrolling are pixels. If the first line displayed is the first line in the text field, scrollV is set to 1 (not 0). Horizontal scrolling is measured in pixels because most fonts are proportionally spaced; that is, the characters can have different widths. Flash performs vertical scrolling by line because users usually want to see a complete line of text rather than a partial line. Even if there are multiple fonts on a line, the height of the line adjusts to fit the largest font in use.
Implementation public function get scrollV():int
public function set scrollV(value:int):void
See also
| selectable | property |
selectable:Boolean [read-write]
A Boolean value that indicates whether the text field is selectable. The value true
indicates that the text is selectable. The selectable property controls whether
a text field is selectable, not whether a text field is editable. A dynamic text field can
be selectable even if it is not editable. If a dynamic text field is not selectable, the user
cannot select its text.
If selectable is set to false, the text in the text field does not
respond to selection commands from the mouse or keyboard, and the text cannot be copied with the
Copy command. If selectable is set to true, the text in the text field
can be selected with the mouse or keyboard, and the text can be copied with the Copy command.
You can select text this way even if the text field is a dynamic text field instead of an input text field.
The default value is true.
public function get selectable():Boolean
public function set selectable(value:Boolean):void
See also
| selectionBeginIndex | property |
selectionBeginIndex:int [read-only]
The zero-based character index value of the first character in the current selection.
For example, the first character is 0, the second character is 1, and so on. If no
text is selected, this property is the value of caretIndex.
public function get selectionBeginIndex():int
See also
printCursorPosition method is called. In that case, the values of the
caretIndex, selectionBeginIndex, and
selectionEndIndex properties are output.
Run this example and try clicking in the TextField to select text. Then click in the field without
selecting text. When you click in the text without making a selection, the
caretIndex property indicates where the insertion point occurs, and the selectionBeginIndex
and selectionEndIndex properties equal the caretIndex property value.
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_caretIndex extends Sprite {
public function TextField_caretIndex() {
var tf:TextField = createTextField(10, 10, 100, 100);
tf.wordWrap = true;
tf.type = TextFieldType.INPUT;
tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
}
private function printCursorPosition(event:MouseEvent):void {
var tf:TextField = TextField(event.target);
trace("caretIndex:", tf.caretIndex);
trace("selectionBeginIndex:", tf.selectionBeginIndex);
trace("selectionEndIndex:", tf.selectionEndIndex);
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
addChild(result);
return result;
}
}
}
| selectionEndIndex | property |
selectionEndIndex:int [read-only]
The zero-based character index value of the last character in the current selection.
For example, the first character is 0, the second character is 1, and so on. If no
text is selected, this property is the value of caretIndex.
public function get selectionEndIndex():int
See also
printCursorPosition method is called. In that case, the values of the
caretIndex, selectionBeginIndex, and
selectionEndIndex properties are output.
Run this example and try clicking in the TextField to select text. Then click in the field without
selecting text. When you click in the text without making a selection, the
caretIndex property indicates where the insertion point occurs, and the selectionBeginIndex
and selectionEndIndex properties equal the caretIndex property value.
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_caretIndex extends Sprite {
public function TextField_caretIndex() {
var tf:TextField = createTextField(10, 10, 100, 100);
tf.wordWrap = true;
tf.type = TextFieldType.INPUT;
tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
}
private function printCursorPosition(event:MouseEvent):void {
var tf:TextField = TextField(event.target);
trace("caretIndex:", tf.caretIndex);
trace("selectionBeginIndex:", tf.selectionBeginIndex);
trace("selectionEndIndex:", tf.selectionEndIndex);
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
addChild(result);
return result;
}
}
}
| sharpness | property |
sharpness:Number [read-write]
The sharpness of the glyph edges in this text field. This property applies
only if the flash.text.AntiAliasType property of the text field is set to
flash.text.AntiAliasType.ADVANCED. The range for
sharpness is a number from -400 to 400. If you attempt to set
sharpness to a value outside that range, Flash sets the property to
the nearest value in the range (either -400 or 400).
The default value is 0.
public function get sharpness():Number
public function set sharpness(value:Number):void
See also
| styleSheet | property |
styleSheet:StyleSheet [read-write]Attaches a style sheet to the text field. For information on creating style sheets, see the StyleSheet class and Programming ActionScript 3.0.
You can change the style sheet associated with a text field at any time. If you change
the style sheet in use, the text field is redrawn with the new style sheet.
You can set the style sheet to null or undefined
to remove the style sheet. If the style sheet in use is removed, the text field is redrawn without a style sheet.
Note: If the style sheet is removed, the contents of both TextField.text and
TextField.htmlText change to incorporate the formatting previously applied by the style sheet. To preserve
the original TextField.htmlText contents without the formatting, save the value in a variable before
removing the style sheet.
public function get styleSheet():StyleSheet
public function set styleSheet(value:StyleSheet):void
See also
| text | property |
text:String [read-write]
A string that is the current text in the text field. Lines are separated by the carriage
return character ('\r', ASCII 13). This property contains unformatted text in the text
field, without HTML tags.
To get the text in HTML form, use the htmlText property.
public function get text():String
public function set text(value:String):void
See also
tf1, and assigns an
HTML-formatted String to its text property. When its htmlText property
is traced, the output is the HTML-formatted String, with additional tags (such as <P> and
<FONT>) automatically added by Flash Player. When the value of the text
property is traced, the unformatted string without HTML tags is displayed.
By way of comparison, the same steps are performed on another TextField object named
tf2, with the addition that a StyleSheet object is assigned to tf2's
styleSheet property before its htmlText property is set. In that case,
when the htmlText property is traced, it only includes the exact HTML text that was
originally assigned to the htmlText property, showing that no additional tags were
added by Flash Player.
package {
import flash.display.Sprite;
import flash.text.StyleSheet;
import flash.text.TextField;
public class TextField_text extends Sprite {
public function TextField_text() {
var tf1:TextField = createTextField(10, 10, 400, 22);
tf1.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";
// htmlText: <P ALIGN="LEFT"><FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0"><b>Lorem ipsum dolor sit amet.</b></FONT></P>
trace("htmlText: " + tf1.htmlText);
// text: Lorem ipsum dolor sit amet.
trace("text: " + tf1.text);
var tf2:TextField = createTextField(10, 50, 400, 22);
tf2.styleSheet = new StyleSheet();
tf2.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";
// htmlText: <b>Lorem ipsum dolor sit amet.</b>
trace("htmlText: " + tf2.htmlText);
// text: Lorem ipsum dolor sit amet.
trace("text: " + tf2.text);
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
addChild(result);
return result;
}
}
}
| textColor | property |
textColor:uint [read-write]
The color of the text in a text field, in hexadecimal format.
The hexadecimal color system uses six digits to represent
color values. Each digit has sixteen possible values or characters. The characters range from
0 to 9 and then A to F. For example, black is 0x000000; white is
0xFFFFFF.
The default value is 0 (0x000000).
public function get textColor():uint
public function set textColor(value:uint):void
textColor property to red (0xFF0000).
package {
import flash.display.Sprite;
import flash.text.TextField;
public class TextField_textColor extends Sprite {
public function TextField_textColor() {
var tf:TextField = createTextField(10, 10, 100, 300);
tf.text = "This will be red text";
tf.textColor = 0xFF0000;
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
addChild(result);
return result;
}
}
}
| textHeight | property |
textHeight:Number [read-only]The height of the text in pixels.
Implementation public function get textHeight():Number
See also
trace statements display the values of the textWidth and
textHeight properties. For comparison, the width and height
properties are also displayed. (Note that the values you see for textHeight and textWidth might
vary depending on the font that is used on your machine).
package {
import flash.display.Sprite;
import flash.text.TextField;
public class TextField_textHeight extends Sprite {
public function TextField_textHeight() {
var tf:TextField = createTextField(10, 10, 100, 150);
tf.text = "Sample text";
trace("textWidth: " + tf.textWidth); // textWidth: 55.75
trace("textHeight: " + tf.textHeight); // textHeight: 13.450000000000001
trace("width: " + tf.width); // width: 100
trace("height: " + tf.height); // height: 150
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
result.border = true;
result.background = true;
addChild(result);
return result;
}
}
}
| textWidth | property |
textWidth:Number [read-only]The width of the text in pixels.
Implementation public function get textWidth():Number
See also
trace statements display the values of the textWidth and
textHeight properties. For comparison, the width and height
properties are also displayed. (Note that the values you see for textHeight and textWidth might
vary depending on the font that is used on your machine).
package {
import flash.display.Sprite;
import flash.text.TextField;
public class TextField_textHeight extends Sprite {
public function TextField_textHeight() {
var tf:TextField = createTextField(10, 10, 100, 150);
tf.text = "Sample text";
trace("textWidth: " + tf.textWidth); // textWidth: 55.75
trace("textHeight: " + tf.textHeight); // textHeight: 13.450000000000001
trace("width: " + tf.width); // width: 100
trace("height: " + tf.height); // height: 150
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
result.border = true;
result.background = true;
addChild(result);
return result;
}
}
}
| thickness | property |
thickness:Number [read-write]
The thickness of the glyph edges in this text field. This property applies only
when flash.text.AntiAliasType is set to flash.text.AntiAliasType.ADVANCED.
The range for thickness is a number from -200 to 200. If you attempt to
set thickness to a value outside that range, the property is set to the
nearest value in the range (either -200 or 200).
The default value is 0.
public function get thickness():Number
public function set thickness(value:Number):void
See also
| type | property |
type:String [read-write]
The type of the text field.
Either one of the following TextFieldType constants: TextFieldType.DYNAMIC,
which specifies a dynamic text field, which a user cannot edit, or TextFieldType.INPUT,
which specifies an input text field, which a user can edit.
The default value is dynamic.
public function get type():String
public function set type(value:String):void
ArgumentError — The type specified is not a member of flash.text.TextFieldType.
|
See also
tfDynamic and
tfInput. Text is entered into both text fields. However,
tfDynamic has its type property set to
TextFieldType.DYNAMIC, and tfInput has its
type property set to TextFieldType.INPUT, so the user can
modify the text in tfInput but can only view the text in tfDynamic.
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_type extends Sprite {
public function TextField_type() {
var tfDynamic:TextField = createTextField(10, 10, 100, 20);
tfDynamic.type = TextFieldType.DYNAMIC;
tfDynamic.text = "hello";
var tfInput:TextField = createTextField(10, 45, 100, 20);
tfInput.type = TextFieldType.INPUT;
tfInput.text = "world";
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
result.background = true;
result.border = true;
addChild(result);
return result;
}
}
}
| useRichTextClipboard | property |
useRichTextClipboard:Boolean [read-write]
Specifies whether to copy and paste the text formatting along with the text. When set to true,
Flash Player will also copy and paste formatting (such as alignment, bold, and italics) when you copy and paste between text fields. Both the origin and destination text fields for the copy and paste procedure must have
useRichTextClipboard set to true. The default value
is false.
public function get useRichTextClipboard():Boolean
public function set useRichTextClipboard(value:Boolean):void
| wordWrap | property |
wordWrap:Boolean [read-write]
A Boolean value that indicates whether the text field has word wrap. If the value of
wordWrap is true, the text field has word wrap;
if the value is false, the text field does not have word wrap. The default
value is false.
public function get wordWrap():Boolean
public function set wordWrap(value:Boolean):void
wordWrap
property to true and setting it to false. Two TextField instances are
created whose contents are too large for their widths. The wordWrap property of
the first (named tfWrap) is set to true; it is set to false
for the second (tfNoWrap).
package {
import flash.display.Sprite;
import flash.text.TextField;
public class TextField_wordWrap extends Sprite {
public function TextField_wordWrap() {
var tfWrap:TextField = createTextField(10, 10, 100, 100);
tfWrap.wordWrap = true;
tfWrap.text = "(wordWrap = true):\nThis is very long text that will certainly extend beyond the width of this text field";
var tfNoWrap:TextField = createTextField(10, 150, 100, 100);
tfNoWrap.wordWrap = false;
tfNoWrap.text = "(wordWrap = false):\nThis is very long text that will certainly extend beyond the width of this text field";
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
result.background = true;
result.border = true;
addChild(result);
return result;
}
}
}
| TextField | () | constructor |
public function TextField()
Creates a new TextField instance. After you create the TextField instance, call the
addChild() or addChildAt() method of the parent
DisplayObjectContainer object to add the TextField instance to the display list.
The default size for a text field is 100 x 100 pixels.
| appendText | () | method |
public function appendText(newText:String):void
Appends the string specified by the newText parameter to the end of the text
of the text field. This method is more efficient than an addition assignment (+=) on
a text property (such as someTextField.text += moreText),
particularly for a text field that contains a significant amount of content.
newText:String — The string to append to the existing text.
|
| getCharBoundaries | () | method |
public function getCharBoundaries(charIndex:int):RectangleReturns a rectangle that is the bounding box of the character.
ParameterscharIndex:int — The zero-based index value for the character (for example, the first
position is 0, the second position is 1, and so on).
|
Rectangle —
A rectangle with x and y minimum and maximum values
defining the bounding box of the character.
|
See also
| getCharIndexAtPoint | () | method |
public function getCharIndexAtPoint(x:Number, y:Number):int
Returns the zero-based index value of the character at the point specified by the x
and y parameters.
x:Number — The x coordinate of the character.
|
|
y:Number — The y coordinate of the character.
|
int —
The zero-based index value of the character (for example, the first position is 0,
the second position is 1, and so on). Returns -1 if the point is not over any character.
|
| getFirstCharInParagraph | () | method |
public function getFirstCharInParagraph(charIndex:int):intGiven a character index, returns the index of the first character in the same paragraph.
ParameterscharIndex:int — The zero-based index value of the character (for example, the first character is 0,
the second character is 1, and so on).
|
int —
The zero-based index value of the first character in the same paragraph.
|
RangeError — The character index specified is out of range.
|
| getImageReference | () | method |
public function getImageReference(id:String):DisplayObject
Returns a DisplayObject reference for the given id, for an image or SWF file
that has been added to an HTML-formatted text field by using an <img> tag.
The <img> tag is in the following format:
<img src = 'filename.jpg' id = 'instanceName' >
Parameters
id:String — The id to match (in the id attribute of the
<img> tag).
|
DisplayObject —
The display object corresponding to the image or SWF file with the matching id
attribute in the <img> tag of the text field. For media loaded from an external source,
this object is a Loader object, and, once loaded, the media object is a child of that Loader object. For media
embedded in the SWF file, this is the loaded object. If there is no <img> tag with
the matching id, the method returns null.
|
See also
| getLineIndexAtPoint | () | method |
public function getLineIndexAtPoint(x:Number, y:Number):int
Returns the zero-based index value of the line at the point specified by the x
and y parameters.
x:Number — The x coordinate of the line.
|
|
y:Number — The y coordinate of the line.
|
int —
The zero-based index value of the line (for example, the first line is 0, the
second line is 1, and so on). Returns -1 if the point is not over any line.
|
| getLineIndexOfChar | () | method |
public function getLineIndexOfChar(charIndex:int):int
Returns the zero-based index value of the line containing the character specified
by the charIndex parameter.
charIndex:int — The zero-based index value of the character (for example, the first character is 0,
the second character is 1, and so on).
|
int —
The zero-based index value of the line.
|
RangeError — The character index specified is out of range.
|
| getLineLength | () | method |
public function getLineLength(lineIndex:int):intReturns the number of characters in a specific text line.
ParameterslineIndex:int — The line number for which you want the length.
|
int —
The number of characters in the line.
|
RangeError — The line number specified is out of range.
|
| getLineMetrics | () | method |
public function getLineMetrics(lineIndex:int):TextLineMetricsReturns metrics information about a given text line.
ParameterslineIndex:int — The line number for which you want metrics information.
|
TextLineMetrics —
A TextLineMetrics object.
|
RangeError — The line number specified is out of range.
|
See also
| getLineOffset | () | method |
public function getLineOffset(lineIndex:int):int
Returns the character index of the first character in the line that
the lineIndex parameter specifies.
lineIndex:int — The zero-based index value of the line (for example, the first line is 0,
the second line is 1, and so on).
|
int —
The zero-based index value of the first character in the line.
|
RangeError — The line number specified is out of range.
|
| getLineText | () | method |
public function getLineText(lineIndex:int):String
Returns the text of the line specified by the lineIndex parameter.
lineIndex:int — The zero-based index value of the line (for example, the first line is 0,
the second line is 1, and so on).
|
String —
The text string contained in the specified line.
|
RangeError — The line number specified is out of range.
|
| getParagraphLength | () | method |
public function getParagraphLength(charIndex:int):int
Given a character index, returns the length of the paragraph containing the given character.
The length is relative to the first character in the paragraph (as returned by
getFirstCharInParagraph()), not to the character index passed in.
charIndex:int — The zero-based index value of the character (for example, the first character is 0,
the second character is 1, and so on).
|
int —
Returns the number of characters in the paragraph.
|
RangeError — The character index specified is out of range.
|
See also
| getTextFormat | () | method |
public function getTextFormat(beginIndex:int = -1, endIndex:int = -1):TextFormat
Returns a TextFormat object that contains formatting information for the range of text that the
beginIndex and endIndex parameters specify. Only properties
that are common to the entire text specified are set in the resulting TextFormat object.
Any property that is mixed, meaning that it has different values
at different points in the text, has a value of null.
If you do not specify values for these parameters, this method is applied to all the text in the text field.
The following table describes three possible usages:
| Usage | Description |
|---|---|
my_textField.getTextFormat() |
Returns a TextFormat object containing formatting information for all text in a text field.
Only properties that are common to all text in the text field are set in the resulting TextFormat
object. Any property that is mixed, meaning that it has different values at different
points in the text, has a value of null. |
my_textField.getTextFormat(beginIndex:Number) |
Returns a TextFormat object containing a copy of the text format of the character at the
beginIndex position. |
my_textField.getTextFormat(beginIndex:Number,endIndex:Number) |
Returns a TextFormat object containing formatting information for the span of
text from beginIndex to endIndex. Only properties that are common
to all of the text in the specified range are set in the resulting TextFormat object. Any property
that is mixed (that is, has different values at different points in the range) has its value set to null. |
beginIndex:int (default = -1) — Optional; an integer that specifies the starting location of a range of text within the text field.
|
|
endIndex:int (default = -1) — Optional; an integer that specifies the ending location of a range of text within the text field.
|
TextFormat —
The TextFormat object that represents the formatting properties for the specified text.
|
RangeError — The beginIndex or endIndex specified is out of range.
|
See also
| replaceSelectedText | () | method |
public function replaceSelectedText(value:String):void
Replaces the current selection with the contents of the value parameter.
The text is inserted at the position of the current selection, using the current default character
format and default paragraph format. The text is not treated as HTML.
You can use the replaceSelectedText() method to insert and delete text without disrupting
the character and paragraph formatting of the rest of the text.
Note: This method will not work if a style sheet is applied to the text field.
Parametersvalue:String — The string to replace the currently selected text.
|
Error — This method cannot be used on a text field with a style sheet.
|
See also
| replaceText | () | method |
public function replaceText(beginIndex:int, endIndex:int, newText:String):void
Replaces the range of characters that the beginIndex and
endIndex parameters specify with the contents
of the newText parameter.
Note: This method will not work if a style sheet is applied to the text field.
ParametersbeginIndex:int — The zero-based index value for the start position of the replacement range.
|
|
endIndex:int — The zero-based index value for end position of the replacement range.
|
|
newText:String — The text to use to replace the specified range of characters.
|
Error — This method cannot be used on a text field with a style sheet.
|
| setSelection | () | method |
public function setSelection(beginIndex:int, endIndex:int):void
Sets as selected the text designated by the index values of the
first and last characters, which are specified with the beginIndex
and endIndex parameters. If the two parameter values are the same,
this method sets the insertion point, just as if you set the
caretIndex property.
beginIndex:int — The zero-based index value of the first character in the selection
(for example, the first character is 0, the second character is 1, and so on).
|
|
endIndex:int — The zero-based index value of the last character in the selection.
|
See also
| setTextFormat | () | method |
public function setTextFormat(format:TextFormat, beginIndex:int = -1, endIndex:int = -1):void
Applies the text formatting that the format parameter specifies to the specified text in a text field.
The value of format must be a TextFormat object that specifies the
desired text formatting changes. Only the non-null properties of format are applied
to the text field. Any property of format that is set to null is not
applied. By default, all of the properties of a newly created TextFormat object are set to null.
Note: This method will not work if a style sheet is applied to the text field.
The setTextFormat() method changes the text formatting applied to a range of
characters or to the entire body of text in a text field. To apply the properties of format to all text in the text
field, do not specify values for beginIndex and endIndex. To apply the
properties of the format to a range of text, specify values for the beginIndex and
the endIndex parameters. You can use the length property to determine
the index values.
The two types of formatting information in a TextFormat object are character level formatting and paragraph level formatting. Each character in a text field might have its own character formatting settings, such as font name, font size, bold, and italic.
For paragraphs, the first character of the paragraph is examined for the paragraph formatting settings for the entire paragraph. Examples of paragraph formatting settings are left margin, right margin, and indentation.
Any text inserted manually by the user, or replaced by means of the
replaceSelectedText() method, receives the text field's default formatting for new text,
and not the formatting specified for the text insertion point. To set a text field's default
formatting for new text, use defaultTextFormat.
format:TextFormat — A TextFormat object that contains character and paragraph formatting information.
|
|||||||||
beginIndex:int (default = -1) — The zero-based index position specifying the first character of the
desired range of text.
|
|||||||||
endIndex:int (default = -1) — The zero-based index position specifying the last character of the desired
range of text.
Notice that any text inserted manually by the user, or replaced by means of the
|
Error — This method cannot be used on a text field with a style sheet.
|
|
RangeError — The beginIndex or endIndex specified is out of range.
|
See also
| change | event |
flash.events.Event
flash.events.Event.CHANGE
Dispatched after a control's value is modified. Contrast this
with the textInput event, which is dispatched before the value is modified.
Unlike the W3C DOM Event Model version of the change event, which dispatches the
event only after the control loses focus, the ActionScript 3.0 version of the
change event is dispatched any time the control changes. For example, if a user
types text into a text field, a change event is dispatched after every keystroke.
Defines the value of the type property of a change event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | true |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The object that has had its value modified.
The target is not always the object in the display list
that registered the event listener. Use the currentTarget
property to access the object in the display list that is currently processing the event. |
| link | event |
flash.events.TextEvent
flash.events.TextEvent.LINK
Dispatched when a user clicks a hyperlink in an HTML-enabled text field, where the URL begins with "event:". The remainder of the URL after "event:" will be placed in the text property of the LINK event.
Note: The default behavior, adding the text to the text field,
occurs only when Flash Player generates the event, which in this case happens when
a user attempts to input text. You cannot put text into a text field by sending it textInput
events.
Defines the value of the type property of a link event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | true |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The text field containing the hyperlink that has been clicked.
The target is not always the object in the display list
that registered the event listener. Use the currentTarget
property to access the object in the display list that is currently processing the event. |
text | The remainder of the URL after "event:" |
playMP3() function is defined.
A TextField object named list is created and populated with HTML text.
The text "Track 1" and "Track 2" are links inside the text field.
The playMP3() function is called when the user clicks either link. The name of the MP3
file, which follows the string "event:" in the href attribute of the
HTML tag, is passed to the linkHandler() method as the text
property of the link event object.
package {
import flash.display.Sprite;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.events.TextEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class TextField_event_link extends Sprite
{
private var myMP3:Sound;
public function TextField_event_link() {
myMP3 = new Sound();
var list:TextField = new TextField();
list.autoSize = TextFieldAutoSize.LEFT;
list.multiline = true;
list.htmlText = "<a href=\"event:track1.mp3\">Track 1</a><br>";
list.htmlText += "<a href=\"event:track2.mp3\">Track 2</a><br>";
addEventListener(TextEvent.LINK, linkHandler);
addChild(list);
}
private function playMP3(mp3:String):void {
try {
myMP3.load(new URLRequest(mp3));
myMP3.play();
}
catch(err:Error) {
trace(err.message);
}
myMP3.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
}
private function linkHandler(linkEvent:TextEvent):void {
playMP3(linkEvent.text);
}
private function errorHandler(errorEvent:IOErrorEvent):void {
trace(errorEvent.text);
}
}
}
| scroll | event |
flash.events.Event
flash.events.Event.SCROLL
Dispatched by a TextField object after the user scrolls.
Defines the value of the type property of a scroll event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The TextField object that has been scrolled.
The target is not always the object in the display list
that registered the event listener. Use the currentTarget
property to access the object in the display list that is currently processing the event. |
| textInput | event |
flash.events.TextEvent
flash.events.TextEvent.TEXT_INPUT
Flash Player dispatches the textInput event when a user enters one or more
characters of text. A number of different
text input methods can generate this event, including standard keyboards,
input method editors (IMEs), voice or speech recognition systems, and even the act
of pasting plain text with no formatting or style information.
Defines the value of the type property of a textInput event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | true |
cancelable | true; call the preventDefault() method
to cancel default behavior. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The text field into which characters are being entered.
The target is not always the object in the display list
that registered the event listener. Use the currentTarget
property to access the object in the display list that is currently processing the event. |
text | The character or sequence of characters entered by the user. |
TextFieldExample class to
display a text message. This is accomplished by using the following steps:
label property of type TextField is created.configureLabel() function.configureLabel() method first creates a new TextField object and assigns it to
the label property, and then sets its parameters to the following:configureLabel() method creates the format variable and assigns it to
a new TextFormat instance with its parameters set to the following:defaultTextFormat property of the label text field
is set to format, and the label instance is added to the display list,
which initially displays a text field with no text on the stage.label text field to
"Hello world and welcome to the show." by calling the
setLabel() method.
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class TextFieldExample extends Sprite {
private var label:TextField;
private var labelText:String = "Hello world and welcome to the show.";
public function TextFieldExample() {
configureLabel();
setLabel(labelText);
}
public function setLabel(str:String):void {
label.text = str;
}
private function configureLabel():void {
label = new TextField();
label.autoSize = TextFieldAutoSize.LEFT;
label.background = true;
label.border = true;
var format:TextFormat = new TextFormat();
format.font = "Verdana";
format.color = 0xFF0000;
format.size = 10;
format.underline = true;
label.defaultTextFormat = format;
addChild(label);
}
}
}
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/201/langref/flash/text/TextField.html