Text object

 < Day Day Up > 

Inheritance Element object > Text object

Availability

Flash MX 2004.

Description

The Text object represents a single text item in a document. All properties of the text pertain to the entire text block.

To set properties of a text run within the text field, see "Property summary for the TextRun object" on page 467. To change properties of a selection within a text field, you can use document.setElementTextAttr() and specify a range of text, or use the current selection.

To set text properties of the selected text field, use document.setElementProperty(). The following example assigns the currently selected text field to the variable textVar:

fl.getDocumentDOM().setElementProperty("variableName", "textVar");

Method summary for the Text object

In addition to the Element object methods, you can use the following methods with the Text object:

Method

Description

text.getTextAttr()

Retrieves the specified attribute for the text identified by the optional startIndex and endIndex parameters.

text.getTextString()

Retrieves the specified range of text.

text.setTextAttr()

Sets the specified attribute associated with the text identified by startIndex and endIndex.

text.setTextString()

Changes the text string within this text object.


Property summary for the Text object

In addition to the Element object properties, the following properties are available for the Text object:

Property

Description

text.accName

A string that is equivalent to the Name field in the Accessibility panel.

text.antiAliasSharpness

A float value that specifies the anti-aliasing sharpness of the text.

text.antiAliasThickness

A float value that specifies the anti-aliasing thickness of the text.

text.autoExpand

A Boolean value that controls the expansion of the bounding width for static text fields or the bounding width and height for dynamic or input text.

text.border

A Boolean value that controls whether Flash shows (true) or hides (false) a border around dynamic or input text.

text.description

A string that is equivalent to the Description field in the Accessibility panel.

text.embeddedCharacters

A string that specifies characters to embed. This is equivalent to entering text in the Character Options dialog box.

text.embedRanges

A string that consists of delimited integers that correspond to the items that can be selected in the Character Options dialog box.

text.fontRenderingMode

A string that specifies the rendering mode for the text.

text.length

Read-only; an integer that represents the number of characters in the text object.

text.lineType

A string that sets the line type to "single line", "multiline", "multiline no wrap", or "password".

text.maxCharacters

An integer that specifies the maximum characters the user can enter into this text object.

text.orientation

A string that specifies the orientation of the text field.

text.renderAsHTML

A Boolean value that controls whether Flash draws the text as HTML and interprets embedded HTML tags.

text.scrollable

A Boolean value that controls whether the text can (TRue) or cannot (false) be scrolled.

text.selectable

A Boolean value that controls whether the text can (true) or cannot (false) be selected. Input text is always selectable.

text.selectionEnd

A zero-based integer that specifies the offset of the end of a text subselection.

text.selectionStart

A zero-based integer that specifies the offset of the beginning of a text subselection.

text.shortcut

A string that is equivalent to the Shortcut field in the Accessibility panel.

text.silent

A Boolean value that specifies whether the object is accessible.

text.tabIndex

An integer that is equivalent to the Tab Index field in the Accessibility panel.

text.textruns

Read-only; an array of TextRun objects.

text.textType

A string that specifies the type of text field. Acceptable values are "static", "dynamic", and "input".

text.useDeviceFonts

A Boolean value. A value of TRue causes Flash to draw text using device fonts.

text.variableName

A string that contains the contents of the text object.


text.antiAliasSharpness

Availability

Flash 8.

Usage

text.antiAliasSharpness

Description

Property; a float value that specifies the anti-aliasing sharpness of the text. This property controls how crisply the text is drawn; higher values specify sharper (or crisper) text. A value of 0 specifies normal sharpness. This property is available only if text.fontRenderingMode is set to "customThicknessSharpness".

Example

See text.fontRenderingMode.

See also

text.antiAliasThickness, text.fontRenderingMode

text.antiAliasThickness

Availability

Flash 8.

Usage

text.antiAliasThickness

Description

Property; a float value that specifies the anti-aliasing thickness of the text. This property controls how thickly the text is drawn, with higher values specifying thicker text. A value of 0 specifies normal thickness. This property is available only if text.fontRenderingMode is set to "customThicknessSharpness".

Example

See text.fontRenderingMode.

See also

text.antiAliasSharpness, text.fontRenderingMode

text.accName

Availability

Flash MX 2004.

Usage

text.accName

Description

Property; a string that is equivalent to the Name field in the Accessibility panel. Screen readers identify objects by reading the name aloud. This property cannot be used with dynamic text.

Example

The following example retrieves the name of the object:

var theName =   fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].accNam   e;

The following example sets the name of the currently selected object:

fl.getDocumentDOM().selection[0].accName = "Home Button";

text.autoExpand

Availability

Flash MX 2004.

Usage

text.autoExpand

Description

Property; a Boolean value. For static text fields, a value of TRue causes the bounding width to expand to show all text. For dynamic or input text fields, a value of TRue causes the bounding width and height to expand to show all text.

Example

The following example sets the autoExpand property to a value of true:

fl.getDocumentDOM().selection[0].autoExpand = true;

text.border

Availability

Flash MX 2004.

Usage

text.border

Description

Property; a Boolean value. A value of true causes Flash to show a border around text.

Example

The following example sets the border property to a value of true:

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].border =   true;

text.description

Availability

Flash MX 2004.

Usage

text.description

Description

Property; a string that is equivalent to the Description field in the Accessibility panel. The description is read by the screen reader.

Example

The following example retrieves the description of the object:

var theDescription =   fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].descri   ption;

The following example sets the description of the object:

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].descripti   on= "Enter your name here";

text.embeddedCharacters

Availability

Flash MX 2004.

Usage

text.embeddedCharacters

Description

Property; a string that specifies characters to embed. This is equivalent to entering text in the Character Options dialog box.

This property works only with dynamic or input text; it generates a warning if used with other text types.

Example

The following example sets the embeddedCharacters property to "abc":

fl.getDocumentDOM().selection[0].embeddedCharacters = "abc";

text.embedRanges

Availability

Flash MX 2004.

Usage

text.embedRanges

Description

Property; a string that consists of delimited integers that correspond to the items that can be selected in the Character Options dialog box. This property works only with dynamic or input text; it is ignored if used with static text.

Note

This property corresponds to the XML file in the Configuration/Font Embedding folder.


Example

The following example sets the embedRanges property to "1|3|7":

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].embedRang   es = "1|3|7";

The following example resets the property:

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].embedRang   es = "";

text.fontRenderingMode

Availability

Flash 8.

Usage

text.fontRenderingMode

Description

Property; a string that specifies the rendering mode for the text. This property affects how the text is displayed both on the Stage and in Flash Player. Acceptable values are described in the following table.

Property value

How text is rendered

device

Renders the text with device fonts.

bitmap

Renders aliased text as a bitmap, or as a pixel font would.

standard

Renders text using the standard anti-aliasing method used by Flash MX 2004. This is the best setting to use for animated, very large, or skewed text.

advanced

Renders text using the FlashType font rendering technology implemented in Flash 8, which produces better anti-aliasing and improves readability, especially for small text.

customThicknessSharpness

Lets you specify custom settings for the sharpness and thickness of the text when using the FlashType font rendering technology implemented in Flash 8.


Example

The following example shows how you can use the customThicknessSharpness value to specify the sharpness and thickness of the text:

fl.getDocumentDOM().setElementProperty("fontRenderingMode",   "customThicknessSharpness"); fl.getDocumentDOM().setElementProperty("antiAliasSharpness", 400); fl.getDocumentDOM().setElementProperty("antiAliasThickness", -200);

See also

text.antiAliasSharpness, text.antiAliasThickness

text.getTextAttr()

Availability

Flash MX 2004.

Usage

text.getTextAttr(attrName [, startIndex [, endIndex]])

Parameters

attrName A string that specifies the name of the TextAttrs object property to be returned.

Note

For a list of possible values for attrName, see Property summary for the TextAttrs object.


startIndex An integer that is the index of first character. This parameter is optional.

endIndex An integer that specifies the end of the range of text, which starts with startIndex and goes up to, but does not include, endIndex. This parameter is optional.

Returns

The value of the attribute specified in the attrName parameter.

Description

Method; retrieves the attribute specified by the attrName parameter for the text identified by the optional startIndex and endIndex parameters. If the attribute is not consistent for the specified range, Flash returns undefined. If you omit the optional parameters startIndex and endIndex, the method uses the entire text range. If you specify only startIndex, the range used is a single character at that position. If you specify both startIndex and endIndex, the range starts from startIndex and goes up to, but does not include, endIndex.

Example

The following example gets the font size of the currently selected text field and shows it:

var TheTextSize = fl.getDocumentDOM().selection[0].getTextAttr("size"); fl.trace(TheTextSize);

The following example gets the text fill color of the selected text field:

var TheFill = fl.getDocumentDOM().selection[0].getTextAttr("fillColor"); fl.trace(TheFill);

The following example gets the size of the third character:

var Char2 = fl.getDocumentDOM().selection[0].getTextAttr("size", 2); fl.trace(Char2);

The following example gets the color of the selected text field from the third through the eighth character:

fl.getDocumentDOM().selection[0].getTextAttr("fillColor", 2, 8);

text.getTextString()

Availability

Flash MX 2004.

Usage

text.getTextString([startIndex [, endIndex] ])

Parameters

startIndex An integer that specifies the index (zero-based) of the first character. This parameter is optional.

endIndex An integer that specifies the end of the range of text, which starts from startIndex and goes up to, but does not include, endIndex. This parameter is optional.

Returns

A string of the text in the specified range.

Description

Method; retrieves the specified range of text. If you omit the optional parameters startIndex and endIndex, the whole text string is returned. If you specify only startIndex, the method returns the string starting at the index location and ending at the end of the field. If you specify both startIndex and endIndex, the method returns the string starts from startIndex and goes up to, but does not include, endIndex.

Example

The following example gets the character(s) from the fifth character through the end of the selected text field:

var myText = fl.getDocumentDOM().selection[0].getTextString(4); fl.trace(myText);

The following example gets the fourth through the ninth characters starting in the selected text field:

var myText = fl.getDocumentDOM().selection[0].getTextString(3, 9); fl.trace(myText);

text.length

Availability

Flash MX 2004.

Usage

text.length

Description

Read-only property; an integer that represents the number of characters in the text object.

Example

The following example returns the number of characters in the selected text:

var textLength = fl.getDocumentDOM().selection[0].length;

text.lineType

Availability

Flash MX 2004.

Usage

text.lineType

Description

Property; a string that sets the line type. Acceptable values are "single line", "multiline", "multiline no wrap", and "password".

This property works only with dynamic or input text and generates a warning if used with static text. The "password" value works only for input text.

Example

The following example sets the lineType property to the value "multiline no wrap":

fl.getDocumentDOM().selection[0].lineType = "multiline no wrap";

text.maxCharacters

Availability

Flash MX 2004.

Usage

text.maxCharacters

Description

Property; an integer that specifies the maximum number of characters the user can enter in this text object.

This property works only with input text; if used with other text types, the property generates a warning.

Example

The following example sets the value of the maxCharacters property to 30:

fl.getDocumentDOM().selection[0].maxCharacters = 30;

text.orientation

Availability

Flash MX 2004.

Usage

text.orientation

Description

Property; a string that specifies the orientation of the text field. Acceptable values are "horizontal", "vertical left to right", and "vertical right to left".

This property works only with static text; it generates a warning if used with other text types.

Example

The following example sets the orientation property to "vertical right to left":

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].orientati   on = "vertical right to left";

text.renderAsHTML

Availability

Flash MX 2004.

Usage

text.renderAsHTML

Description

Property; a Boolean value. If the value is true, Flash draws the text as HTML and interprets embedded HTML tags.

This property works only with dynamic or input text; it generates a warning if used with other text types.

Example

The following example sets the renderAsHTML property to true:

fl.getDocumentDOM().selection[0].renderAsHTML = true;

text.scrollable

Availability

Flash MX 2004.

Usage

text.scrollable

Description

Property; a Boolean value. If the value is TRue, the text can be scrolled.

This property works only with dynamic or input text; it generates a warning if used with static text.

Example

The following example sets the scrollable property to false:

fl.getDocumentDOM().selection[0].scrollable = false;

text.selectable

Availability

Flash MX 2004.

Usage

text.selectable

Description

Property; a Boolean value. If the value is TRue, the text can be selected.

Input text is always selectable. It generates a warning when set to false and used with input text.

Example

The following example sets the selectable property to TRue:

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].selectabl   e = true;

text.selectionEnd

Availability

Flash MX 2004.

Usage

text.selectionEnd

Description

Property; a zero-based integer that specifies the end of a text subselection. For more information, see text.selectionStart.

text.selectionStart

Availability

Flash MX 2004.

Usage

text.selectionStart

Description

Property; a zero-based integer that specifies the beginning of a text subselection. You can use this property with text.selectionEnd to select a range of characters. Characters up to, but not including, text.selectionEnd are selected. See text.selectionEnd.

  • If there is an insertion point or no selection, text.selectionEnd is equal to text.selectionStart.

  • If text.selectionStart is set to a value greater than text.selectionEnd, text.selectionEnd is set to text.selectionStart, and no text is selected.

Example

The following example sets the start of the text subselection to the sixth character:

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].selection   Start = 5;

The following example selects the characters "Barbara" from a text field that contains the text "My name is Barbara" and formats them as bold and green:

fl.getDocumentDOM().selection[0].selectionStart = 11; fl.getDocumentDOM().selection[0].selectionEnd = 18; var s = fl.getDocumentDOM().selection[0].selectionStart; var e = fl.getDocumentDOM().selection[0].selectionEnd; fl.getDocumentDOM().setElementTextAttr('bold', true, s, e); fl.getDocumentDOM().setElementTextAttr("fillColor", "#00ff00", s, e);

text.setTextAttr()

Availability

Flash MX 2004.

Usage

text.setTextAttr(attrName, attrValue [, startIndex [, endIndex]])

Parameters

attrName A string that specifies the name of the TextAttrs object property to change.

attrValue The value for the TextAttrs object property.

Note

For a list of possible values for attrName and attrValue, see "Property summary for the TextAttrs object" on page 457.


startIndex An integer that is the index (zero-based) of the first character in the array. This parameter is optional.

endIndex An integer that specifies the index of the end point in the selected text string, which starts at startIndex and goes up to, but does not include, endIndex. This parameter is optional.

Returns

Nothing.

Description

Method; sets the attribute specified by the attrName parameter associated with the text identified by startIndex and endIndex to the value specified by attrValue. This method can be used to change attributes of text that might span TextRun elements (see TextRun object), or that are portions of existing TextRun elements. Using it may change the position and number of TextRun elements within this object's text.texTRuns array (see text.texTRuns).

If you omit the optional parameters, the method uses the entire text object's character range. If you specify only startIndex, the range is a single character at that position. If you specify both startIndex and endIndex, the range starts from startIndex and goes up to, but does not include, the character located at endIndex.

Example

The following example sets the selected text field to italic:

fl.getDocumentDOM().selection[0].setTextAttr("italic", true);

The following example sets the size of the third character to 10:

fl.getDocumentDOM().selection[0].setTextAttr("size", 10, 2);

The following example sets the color to red for the third through the eighth character of the selected text:

fl.getDocumentDOM().selection[0].setTextAttr("fillColor", 0xff0000, 2, 8);

text.setTextString()

Availability

Flash MX 2004.

Usage

text.setTextString(text [, startIndex [, endIndex]])

Parameters

text A string that consists of the characters to be inserted into this text object.

startIndex An integer that specifies the index (zero-based) of the character in the string where the text will be inserted. This parameter is optional.

endIndex An integer that specifies the index of the end point in the selected text string. The new text overwrites the text from startIndex up to, but not including, endIndex. This parameter is optional.

Returns

Nothing.

Description

Property; changes the text string within this text object. If you omit the optional parameters, the whole text object is replaced. If you specify only startIndex, the specified string is inserted at the startIndex position. If you specify both startIndex and endIndex, the specified string replaces the segment of text starting from startIndex up to, but not including, endIndex.

Example

The following example assigns the string "this is a string" to the selected text field:

fl.getDocumentDOM().selection[0].setTextString("this is a string");

The following example inserts the string "abc" beginning at the fifth character of the selected text field:

fl.getDocumentDOM().selection[0].setTextString("01234567890"); fl.getDocumentDOM().selection[0].setTextString("abc", 4); // text field is now "0123abc4567890"

The following example replaces the text from the third through the eighth character of the selected text string with the string "abcdefghij". Characters between startIndex and endIndex are overwritten. Characters beginning with endIndex follow the inserted string.

fl.getDocumentDOM().selection[0].setTextString("01234567890"); fl.getDocumentDOM().selection[0].setTextString("abcdefghij", 2, 8); // text field is now 01abcdefghij890"

text.shortcut

Availability

Flash MX 2004.

Usage

text.shortcut

Description

Property; a string that is equivalent to the Shortcut field in the Accessibility panel. The shortcut is read by the screen reader. This property cannot be used with dynamic text.

Example

The following example gets the shortcut key of the selected object and shows the value:

var theShortcut = fl.getDocumentDOM().selection[0].shortcut; fl.trace(theShortcut);

The following example sets the shortcut key of the selected object:

fl.getDocumentDOM().selection[0].shortcut = "Ctrl+i";

text.silent

Availability

Flash MX 2004.

Usage

text.silent

Description

Property; a Boolean value that specifies whether the object is accessible. This is equivalent to the inverse logic of the Make Object Accessible setting in the Accessibility panel. That is, if silent is true, Make Object Accessible is deselected. If it is false, Make Object Accessible is selected.

Example

The following example determines if the object is accessible (a value of false means that it is accessible):

var isSilent =   fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].silent   ;

The following example sets the object to be accessible:

fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0].silent =   false;

text.tabIndex

Availability

Flash MX 2004.

Usage

text.tabIndex

Description

Property; an integer that is equivalent to the Tab Index field in the Accessibility panel. This value lets you determine the order in which objects are accessed when the user presses the Tab key.

Example

The following example gets the tabIndex of the currently selected object:

var theTabIndex = fl.getDocumentDOM().selection[0].tabIndex;

The following example sets the tabIndex of the currently selected object:

fl.getDocumentDOM().selection[0].tabIndex = 1;

text.textRuns

Availability

Flash MX 2004.

Usage

text.textRuns

Description

Read-only property; an array of TextRun objects (see TextRun object).

Example

The following example stores the value of the texTRuns property in the myTexTRuns variable:

var myTextRuns = fl.getDocumentDOM().selection[0].textRuns;

text.textType

Availability

Flash MX 2004.

Usage

text.textType

Description

Property; a string that specifies the type of text field. Acceptable values are "static", "dynamic", and "input".

Example

The following example sets the textType property to "input":

fl.getDocumentDOM().selection[0].textType = "input";

text.useDeviceFonts

Availability

Flash MX 2004.

Usage

text.useDeviceFonts

Description

Property; a Boolean value. A value of true causes Flash to draw text using device fonts.

Example

The following example causes Flash to use device fonts when drawing text.

fl.getDocumentDOM().selection[0].useDeviceFonts = true;

text.variableName

Availability

Flash MX 2004.

Usage

text.variableName

Description

Property; a string that contains the name of the variable associated with the text object. This property works only with dynamic or input text; it generates a warning if used with other text types.

     < Day Day Up > 


    Developing Extensions for Macromedia Flash 8
    Developing Extensions for Macromedia Flash 8
    ISBN: 032139416X
    EAN: 2147483647
    Year: 2005
    Pages: 81

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net