View comments | RSS feed

TextField


Object
    |
    +-TextField

public dynamic class TextField
extends Object

The TextField class is used to create areas for text display and input. All dynamic and input text fields in a SWF file are instances of the TextField class. You can give a text field an instance name in the Property inspector and use the methods and properties of the TextField class to manipulate it with ActionScript. TextField instance names are displayed in the Movie Explorer and in the Insert Target Path dialog box in the Actions panel.

To create a text field dynamically, you do not use the new operator. Instead, you use MovieClip.createTextField().

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. In Flash Player 7 and later, you can apply Cascading Style Sheets (CSS) styles to text fields 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. In Flash Player 7 and later, HTML text that you assign to a text field can contain embedded media (movie clips, SWF files, JPEG files, GIF files, PNG 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.

Availability: ActionScript 1.0; Flash Player 6

See also

Object, createTextField (MovieClip.createTextField method)

Property summary

Modifiers

Property

Description

 

_alpha:Number

Sets or retrieves the alpha transparency value of the text field.

 

antiAliasType:String

The type of anti-aliasing used for this TextField instance.

 

autoSize:Object

Controls automatic sizing and alignment of text fields.

 

background:Boolean

Specifies if the text field has a background fill.

 

backgroundColor:Number

The color of the text field background.

 

border:Boolean

Specifies if the text field has a border.

 

borderColor:Number

The color of the text field border.

 

bottomScroll:Number [read-only]

An integer (one-based index) that indicates the bottommost line that is currently visible the text field.

 

condenseWhite:Boolean

A Boolean value that specifies whether extra white space (spaces, line breaks, and so on) in an HTML text field should be removed when the field is rendered in a browser.

 

embedFonts:Boolean

Specifies whether to render using embedded font outlines.

 

filters:Array

An indexed array containing each filter object currently associated with the text field.

 

gridFitType:String

The type of grid fitting used for this TextField instance.

 

_height:Number

The height of the text field in pixels.

 

_highquality:Number

Deprecated since Flash Player 7. This property was deprecated in favor of TextField._quality.

Specifies the level of anti-aliasing applied to the current SWF file.

 

hscroll:Number

Indicates the current horizontal scrolling position.

 

html:Boolean

A flag that indicates whether the text field contains an HTML representation.

 

htmlText:String

If the text field is an HTML text field, this property contains the HTML representation of the text field's contents.

 

length:Number [read-only]

Indicates the number of characters in a text field.

 

maxChars:Number

Indicates the maximum number of characters that the text field can contain.

 

maxhscroll:Number [read-only]

Indicates the maximum value of TextField.hscroll.

 

maxscroll:Number [read-only]

Indicates the maximum value of TextField.scroll.

 

menu:ContextMenu

Associates the ContextMenu object contextMenu with the text field my_txt.

 

mouseWheelEnabled:Boolean

A Boolean value that indicates whether Flash Player should automatically scroll multiline text fields when the mouse pointer clicks a text field and the user rolls the mouse wheel.

 

multiline:Boolean

Indicates whether the text field is a multiline text field.

 

_name:String

The instance name of the text field.

 

_parent:MovieClip

A reference to the movie clip or object that contains the current text field or object.

 

password:Boolean

Specifies whether the text field is a password text field.

 

_quality:String

The rendering quality used for a SWF file.

 

restrict:String

Indicates the set of characters that a user may enter into the text field.

 

_rotation:Number

The rotation of the text field, in degrees, from its original orientation.

 

scroll:Number

The vertical position of text in a text field.

 

selectable:Boolean

A Boolean value that indicates whether the text field is selectable.

 

sharpness:Number

The sharpness of the glyph edges in this TextField instance.

 

_soundbuftime:Number

The number of seconds a sound prebuffers before it starts to stream.

 

styleSheet:StyleSheet

Attaches a style sheet to the text field.

 

tabEnabled:Boolean

Specifies whether the text field is included in automatic tab ordering.

 

tabIndex:Number

Lets you customize the tab ordering of objects in a SWF file.

 

_target:String [read-only]

The target path of the text field instance.

 

text:String

Indicates the current text in the text field.

 

textColor:Number

Indicates the color of the text in a text field.

 

textHeight:Number

Indicates the height of the text.

 

textWidth:Number

Indicates the width of the text.

 

thickness:Number

The thickness of the glyph edges in this TextField instance.

 

type:String

Specifies the type of text field.

 

_url:String [read-only]

Retrieves the URL of the SWF file that created the text field.

 

variable:String

The name of the variable that the text field is associated with.

 

_visible:Boolean

A Boolean value that indicates whether the text field my_txt is visible.

 

_width:Number

The width of the text field, in pixels.

 

wordWrap:Boolean

A Boolean value that indicates if the text field has word wrap.

 

_x:Number

An integer that sets the x coordinate of a text field relative to the local coordinates of the parent movie clip.

 

_xmouse:Number [read-only]

Returns the x coordinate of the mouse position relative to the text field.

 

_xscale:Number

Determines the horizontal scale of the text field as applied from the registration point of the text field, expressed as a percentage.

 

_y:Number

The y coordinate of a text field relative to the local coordinates of the parent movie clip.

 

_ymouse:Number [read-only]

Indicates the y coordinate of the mouse position relative to the text field.

 

_yscale:Number

The vertical scale of the text field as applied from the registration point of the text field, expressed as a percentage.

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Event summary

Event

Description

onChanged = function(changedField:TextField) {}

Event handler/listener; invoked when the content of a text field changes.

onKillFocus = function(newFocus:Object) {}

Invoked when a text field loses keyboard focus.

onScroller = function(scrolledField:TextField) {}

Event handler/listener; invoked when one of the text field scroll properties changes.

onSetFocus = function(oldFocus:Object) {}

Invoked when a text field receives keyboard focus.

Method summary

Modifiers

Signature

Description

 

addListener(listener:Object) : Boolean

Registers an object to receive TextField event notifications.

 

getDepth() : Number

Returns the depth of a text field.

static

getFontList() : Array

Returns the names of fonts on the player's host system as an array.

 

getNewTextFormat() : TextFormat

Returns a TextFormat object containing a copy of the text field's text format object.

 

getTextFormat([beginIndex:Number], [endIndex:Number]) : TextFormat

Returns a TextFormat object for a character, a range of characters, or an entire TextField object.

 

removeListener(listener:Object) : Boolean

Removes a listener object previously registered to a text field instance with TextField.addListener().

 

removeTextField() : Void

Removes the text field.

 

replaceSel(newText:String) : Void

Replaces the current selection with the contents of the newText parameter.

 

replaceText(beginIndex:Number, endIndex:Number, newText:String) : Void

Replaces a range of characters, specified by the beginIndex and endIndex parameters, in the specified text field with the contents of the newText parameter.

 

setNewTextFormat(tf:TextFormat) : Void

Sets the default new text format of a text field.

 

setTextFormat([beginIndex:Number], [endIndex:Number], textFormat:TextFormat) : Void

Applies the text formatting specified by the textFormat parameter to some or all of the text in a text field.

Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


No screen name said on Oct 24, 2005 at 6:16 PM :
Is there a way to make a dynamic textfield resize to match the height of the text inside it?

I've set up my own simple scrolling script to allow some added functionality I needed, but the height of the field is a problem.

Setting it to bigger than I will ever need isn't an adequate solution as this doesn't tell me the height of the actual content.

Anyone reading this have any ideas?
djtechwriter said on Oct 25, 2005 at 5:20 PM :
No screen name,

See TextField.autoSize at http://livedocs.macromedia.com/flash/8/main/00002734.html.
intangibleinc said on Feb 13, 2006 at 5:02 PM :
Is there any way to have the horizontal scrollbar adjust to allow for scrolling even when wordWrap is true? There are instances when you want the words to Wrap and also have horizontal scrolling (ie. when their is an embedded img tag in the htmlText of the textField) I am guessing that it will require some hacking of the component. Can you assist me in where to start in doing so?
No screen name said on Feb 22, 2007 at 4:38 AM :
is there any way to add letter spacing to dynamic field ??
TessandraFae said on Jun 22, 2007 at 10:35 AM :
I have dynamically created textfields in a movieclip. The left panel creates input textfields and the center creates the "output" textfields. I have shared fonts called myArial, myArial-Bold, myArial-Italic, and myArial-BoldItalic.

The input fields use the standard Arial font, but the output textfields use myArial-Bold on creation. They display just fine.

Now I have a piece of code that takes whatever is in the input textfields and puts it in the output textfields. For some reason, the output textfields receive the text and the default Arial font, even though I've used TextFormat to make sure new text gets the myArial-Bold font.

Even worse, after the code transfers the text to the output textfields, if I attempt to TextFormat that output to myArial-Bold, it will not respond. It keeps the default Arial font.

The one line that's causing all the damage:

newOutputPanel.output_txt.text = newPanel.input_txt.text;

i thought this only brings across the text words, not the format. what's the deal?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002730.html