Package | flash.text.engine |
Class | public final class TextElement |
Inheritance | TextElement ContentElement Object |
Language version: | ActionScript 3.0 |
Runtime version: | AIR 1.5 |
content
property of a TextBlock object to create a block of text. Assign it to a GroupElement object to combine it with other text
and graphic elements as a unit. Use the ElementFormat class to format the text.
See also
Property | Defined by | ||
---|---|---|---|
constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | ||
elementFormat : ElementFormat
The ElementFormat object used for the element.
| ContentElement | ||
eventMirror : EventDispatcher
The
EventDispatcher object that receives copies of every
event dispatched to valid text lines based on this content element. | ContentElement | ||
groupElement : GroupElement
The GroupElement object that contains this element, or
null if it is not in a group. | ContentElement | ||
prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | ||
rawText : String
A copy of the text in the element, including any U+FDEF characters.
| ContentElement | ||
text : String
[write-only]
Receives the text that is the content of the element.
| TextElement | ||
textBlock : TextBlock
The TextBlock to which this element belongs.
| ContentElement | ||
textBlockBeginIndex : int
The index in the text block of the first character of this element.
| ContentElement | ||
textRotation : String
The rotation to apply to the element as a unit.
| ContentElement | ||
userData : *
Provides a way for an application to associate arbitrary data with the element.
| ContentElement |
Method | Defined by | ||
---|---|---|---|
TextElement(text:String = null, elementFormat:ElementFormat = null, eventMirror:EventDispatcher = null, textRotation:String = "rotate0")
Creates a new TextElement instance.
| TextElement | ||
Indicates whether an object has a specified property defined.
| Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | ||
Indicates whether the specified property exists and is enumerable.
| Object | ||
Replaces the range of characters that the
beginIndex and
endIndex parameters specify with the contents
of the newText parameter. | TextElement | ||
Sets the availability of a dynamic property for loop operations.
| Object | ||
Returns the string representation of this object, formatted according to locale-specific conventions.
| Object | ||
Returns the string representation of the specified object.
| Object | ||
Returns the primitive value of the specified object.
| Object |
text | property |
text:String
[write-only]
Language version: | ActionScript 3.0 |
Runtime version: | AIR 1.5 |
Receives the text that is the content of the element.
The default value is null
.
public function set text(value:String):void
TextElement | () | constructor |
public function TextElement(text:String = null, elementFormat:ElementFormat = null, eventMirror:EventDispatcher = null, textRotation:String = "rotate0")
Language version: | ActionScript 3.0 |
Runtime version: | AIR 1.5 |
Creates a new TextElement instance.
Parameterstext:String (default = null ) — The text for the element. The default value is null .
|
|
elementFormat:ElementFormat (default = null ) — The element format for the text in the element. The default value is null .
|
|
eventMirror:EventDispatcher (default = null ) — The EventDispatcher object that receives copies of every
event dispatched to text lines based on this content element. The default value is null .
|
|
textRotation:String (default = "rotate0 ") — The rotation applied the element as a unit. Use TextRotation
constants for this property. The default value is TextRotation.ROTATE_0 .
|
content
property of a TextBlock. It calls the createLines() function to break the
block of text into lines of 150 pixels each.
package { import flash.display.Sprite; import flash.text.engine.TextBlock; import flash.text.engine.TextElement; import flash.text.engine.TextLine; import flash.text.engine.ElementFormat; public class TextElementExample extends Sprite { public function TextElementExample():void { var str:String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut " + "enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " + "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit " + "in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur " + "sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."; var format:ElementFormat = new ElementFormat(null, 12, 0xCC0000); var textElement:TextElement = new TextElement(str, format); var textBlock:TextBlock = new TextBlock(); textBlock.content = textElement; createLines(textBlock); } private function createLines(textBlock:TextBlock):void { var yPos = 20; var textLine:TextLine = textBlock.createTextLine (null, 150); while (textLine) { addChild(textLine); textLine.x = 15; yPos += textLine.textHeight+2; textLine.y = yPos; textLine = textBlock.createTextLine(textLine, 150); } } } }
replaceText | () | method |
public function replaceText(beginIndex:int, endIndex:int, newText:String):void
Language version: | ActionScript 3.0 |
Runtime version: | AIR 1.5 |
Replaces the range of characters that the beginIndex
and
endIndex
parameters specify with the contents
of the newText
parameter. The beginIndex
and
endIndex
values refer to the current contents of text
.
To delete text, pass null
for newText
.
To insert text, pass the same value for beginIndex
and endIndex
.
The new text is inserted before the specified index.
To append text, pass text.length
for beginIndex
and endIndex
.
To set all the text, pass 0 for beginIndex
and text.length
for endIndex
.
beginIndex:int — The zero-based index value for the start position of the replacement range.
|
|
endIndex:int — The zero-based index value following the end position of the replacement range.
|
|
newText:String — The text to use to replace the specified range of characters.
|
RangeError — The beginIndex or endIndex specified is out of range.
|
replaceText()
several times to do the following:
package { import flash.display.Sprite; import flash.text.engine.FontDescription; import flash.text.engine.ElementFormat; import flash.text.engine.TextElement; import flash.text.engine.TextBlock; import flash.text.engine.TextLine; public class TextElement_replaceTextExample extends Sprite { public function TextElement_replaceTextExample():void { var str:String = "0123456"; var fontDescription:FontDescription = new FontDescription("Arial"); var format:ElementFormat = new ElementFormat(fontDescription); format.fontSize = 14; var textElement:TextElement = new TextElement(str, format); var textBlock:TextBlock = new TextBlock(); textBlock.content = textElement; textElement.replaceText(0, 0, "abc"); createLine(textBlock, 20); //"abc0123456" textElement.replaceText(10, 10, "abc"); createLine(textBlock, 40); // "abc0123456abc" textElement.replaceText(5, 8, "abc"); createLine(textBlock, 60); // "abc01abc56abc" textElement.replaceText(0, 13, "abc"); createLine(textBlock, 80); // "abc" textElement.replaceText(0, 3, "That's all she wrote!"); createLine(textBlock, 100); // "That's all she wrote" */ } private function createLine(textBlock:TextBlock, y:Number):void { var textLine:TextLine = textBlock.createTextLine(null, 150); textLine.x = 10; textLine.y = y; addChild(textLine); } } }