| 包 | flash.text.engine |
| 类 | public final class TextLine |
| 继承 | TextLine DisplayObjectContainer InteractiveObject DisplayObject EventDispatcher Object |
| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
无法从 ActionScript 代码直接创建 TextLine 对象。如果调用 new TextLine(),则会引发异常。要创建 TextLine 对象,请调用 TextBlock 的 createTextLine() 方法。
TextLine 封装通过描述行 atom 属性的某些方法呈现其内容和提供交互性所需的最小信息。术语“atom”既可指图形元素,也可表示字符(包括由字符合并起来的组合),是组成文本行的不可分割的实体。
在针对文本行的正常事件调度完成后,如果该文本行有效,则将事件镜像到分配给该文本行的内容元素对象的 eventMirror 属性中指定的事件调度程序。这些对象记录在 TextLine.mirrorRegions 属性中。如果事件传播失败或被中止,或者如果文本行无效,则不会镜像事件。
镜像鼠标事件是一个特例。由于镜像区域并不实际显示对象,因此将为这些区域模拟 mouseOver 和 mouseOut 事件。并不模拟 rollOver 和 rollOut 事件。忽略所有自然发生的 mouseOver、mouseOut、rollOver 和 rollOut 事件(无论这些事件将文本行作为目标还是将文本行的子项作为目标),而不会对其进行镜像。
文本行对象的原点是基线的开始位置。如果在罗马字基线上没有设置包含拉丁文本的行的垂直位置(y 属性),则只有文本的下行字符将显示在向其中添加文本行的 Sprite 的顶部之下。请参阅下图:
TextLine 类具有多个祖代类(DisplayObjectContainer、InteractiveObject、DisplayObject 和 EventDispatcher),并从这些祖代类继承属性和方法。以下继承的属性不适用于 TextLine 对象:
-
contextMenu -
focusRect -
tabChildren -
tabEnabled -
tabIndex
如果您尝试设置这些属性,则文本引擎将引发错误:IllegalOperationError。您可以读取这些属性,但是它们将始终包含默认值。
相关 API 元素
| 属性 | 由以下参数定义 | ||
|---|---|---|---|
![]() | accessibilityImplementation : AccessibilityImplementation
InteractiveObject 实例的当前辅助功能实现 (AccessibilityImplementation)。 | InteractiveObject | |
![]() | accessibilityProperties : AccessibilityProperties
此显示对象的当前辅助功能选项。 | DisplayObject | |
![]() | alpha : Number
表示指定对象的 Alpha 透明度值。 | DisplayObject | |
| ascent : Number [只读]
指定从基线到行中最高字符顶部的像素数。 | TextLine | ||
| atomCount : int [只读]
行中的 atom 数,即不可分割的元素数,其中包括空格和图形元素。 | TextLine | ||
![]() | blendMode : String
BlendMode 类中的一个值,用于指定要使用的混合模式。 | DisplayObject | |
![]() | blendShader : Shader [只写]
设置用于混合前景和背景的着色器。 | DisplayObject | |
![]() | cacheAsBitmap : Boolean
如果设置为 true,则 Flash 运行时将缓存显示对象的内部位图表示形式。 | DisplayObject | |
![]() | cacheAsBitmapMatrix : Matrix
如果为非 null,则 Matrix 对象会定义显示对象在 cacheAsBitmap 设置为 true 时的呈现方式。 | DisplayObject | |
![]() | constructor : Object
对类对象或给定对象实例的构造函数的引用。 | Object | |
![]() | contextMenu : NativeMenu
指定与此对象相关联的上下文菜单。 | InteractiveObject | |
| descent : Number [只读]
指定从基线到行中最低字符底部的像素数。 | TextLine | ||
![]() | doubleClickEnabled : Boolean
指定此对象是否接收 doubleClick 事件。 | InteractiveObject | |
![]() | filters : Array
包含当前与显示对象关联的每个滤镜对象的索引数组。 | DisplayObject | |
![]() | focusRect : Object
指定此对象是否显示焦点矩形。 | InteractiveObject | |
| hasGraphicElement : Boolean [只读]
表示文本行是否包含任何图形元素。 | TextLine | ||
| hasTabs : Boolean [只读]
表示文本行是否包含任何选项卡。 | TextLine | ||
![]() | height : Number
表示显示对象的高度,以像素为单位。 | DisplayObject | |
![]() | loaderInfo : LoaderInfo [只读]
返回一个 LoaderInfo 对象,其中包含加载此显示对象所属的文件的相关信息。 | DisplayObject | |
![]() | mask : DisplayObject
调用显示对象被指定的 mask 对象遮罩。 | DisplayObject | |
![]() | metaData : Object
如果元数据是通过 PlaceObject4 标记与此 DisplayObject 的实例一起存储在 SWF 文件中的,则获取 DisplayObject 实例的元数据对象。 | DisplayObject | |
| mirrorRegions : Vector.<flash.text.engine:TextLineMirrorRegion> [只读]
包含与行相关联的 TextLineMirrorRegion 对象的矢量;如果没有这样的对象,则为 null。 | TextLine | ||
![]() | mouseChildren : Boolean
确定对象的子级是否支持鼠标或用户输入设备。 | DisplayObjectContainer | |
![]() | mouseEnabled : Boolean
指定此对象是否接收鼠标或其他用户输入、消息。 | InteractiveObject | |
![]() | mouseX : Number [只读]
表示此鼠标或用户输入设备位置的 x 坐标,以像素为单位。 | DisplayObject | |
![]() | mouseY : Number [只读]
表示此鼠标或用户输入设备位置的 y 坐标,以像素为单位。 | DisplayObject | |
![]() | name : String
表示 DisplayObject 的实例名称。 | DisplayObject | |
![]() | needsSoftKeyboard : Boolean
指定当该 InteractiveObject 实例获得焦点时,是否显示虚拟键盘(显示在屏幕上的软键盘)。 | InteractiveObject | |
| nextLine : flash.text.engine:TextLine [只读]
TextBlock 中的下一个 TextLine;如果当前行是块中的最后一行或行的 validity 为 TextLineValidity.STATIC,则为 null。 | TextLine | ||
![]() | numChildren : int [只读]
返回此对象的子项数目。 | DisplayObjectContainer | |
![]() | opaqueBackground : Object
指定显示对象是否由于具有某种背景颜色而不透明。 | DisplayObject | |
![]() | parent : DisplayObjectContainer [只读]
表示包含此显示对象的 DisplayObjectContainer 对象。 | DisplayObject | |
| previousLine : flash.text.engine:TextLine [只读]
TextBlock 中的上一个 TextLine;如果行是块中的第一行或行的 validity 为 TextLineValidity.STATIC,则为 null。 | TextLine | ||
| rawTextLength : int [只读]
文本块中构成行的原始文本的长度,包括表示图形元素的 U+FDEF 字符以及构成该行的一部分但不会显示的任何尾随空格。 | TextLine | ||
![]() | root : DisplayObject [只读]
对于加载的 SWF 文件中的显示对象,root 属性是此 SWF 文件所表示的显示列表树结构部分中的顶级显示对象。 | DisplayObject | |
![]() | rotation : Number
表示 DisplayObject 实例距其原始方向的旋转程度,以度为单位。 | DisplayObject | |
![]() | rotationX : Number
表示 DisplayObject 实例相对于 3D 父容器距离其原始方向的 x 轴旋转(以度为单位)。 | DisplayObject | |
![]() | rotationY : Number
表示 DisplayObject 实例相对于 3D 父容器距离其原始方向的 y 轴旋转(以度为单位)。 | DisplayObject | |
![]() | rotationZ : Number
表示 DisplayObject 实例相对于 3D 父容器距离其原始方向的 z 轴旋转(以度为单位)。 | DisplayObject | |
![]() | scale9Grid : Rectangle
当前有效的缩放网格。 | DisplayObject | |
![]() | scaleX : Number
表示从注册点开始应用的对象的水平缩放比例(百分比)。 | DisplayObject | |
![]() | scaleY : Number
表示从对象注册点开始应用的对象的垂直缩放比例(百分比)。 | DisplayObject | |
![]() | scaleZ : Number
表示从对象的注册点开始应用的对象的深度缩放比例(百分比)。 | DisplayObject | |
![]() | scrollRect : Rectangle
显示对象的滚动矩形范围。 | DisplayObject | |
![]() | softKeyboard : String
控制软键盘的外观。 | InteractiveObject | |
![]() | softKeyboardInputAreaOfInterest : Rectangle
定义当显示软键盘时应在屏幕上保留的区域(在 iOS 上不支持)。 | InteractiveObject | |
| specifiedWidth : Number [只读]
使用 TextBlock.createTextLine() 方法创建行时为该方法指定的宽度。 | TextLine | ||
![]() | stage : Stage [只读]
显示对象的舞台。 | DisplayObject | |
![]() | tabChildren : Boolean
确定对象的子项是否支持 Tab 键。 | DisplayObjectContainer | |
![]() | tabEnabled : Boolean
指定此对象是否遵循 Tab 键顺序。 | InteractiveObject | |
![]() | tabIndex : int
指定 SWF 文件中的对象按 Tab 键顺序排列。 | InteractiveObject | |
| textBlock : flash.text.engine:TextBlock [只读]
包含此文本行的 TextBlock;如果该行的 validity 为 TextLineValidity.STATIC,则为 null,表示已切断行与文本块之间的连接。 | TextLine | ||
| textBlockBeginIndex : int [只读]
文本块原始文本中行的第一个字符的索引。 | TextLine | ||
| textHeight : Number [只读]
文本行的逻辑高度,即 ascent + descent。 | TextLine | ||
![]() | textSnapshot : flash.text:TextSnapshot [只读]
返回此 DisplayObjectContainer 实例的 TextSnapshot 对象。 | DisplayObjectContainer | |
| textWidth : Number [只读]
文本行的逻辑宽度,即文本引擎用于布置行的宽度。 | TextLine | ||
| totalAscent : Number [只读]
指定从基线到行中最高字符或图形顶部的像素数。 | TextLine | ||
| totalDescent : Number [只读]
指定从基线到行中最低字符或图形底部的像素数。 | TextLine | ||
| totalHeight : Number [只读]
文本行的总逻辑高度,即 totalAscent + totalDescent。 | TextLine | ||
![]() | transform : flash.geom:Transform
一个对象,具有与显示对象的矩阵、颜色转换和像素范围有关的属性。 | DisplayObject | |
| unjustifiedTextWidth : Number [只读]
行未两端对齐时的宽度。 | TextLine | ||
| userData : *
为应用程序提供一种将任意数据与文本行相关联的方法。 | TextLine | ||
| validity : String
指定文本行的当前有效性。 | TextLine | ||
![]() | visible : Boolean
显示对象是否可见。 | DisplayObject | |
![]() | width : Number
表示显示对象的宽度,以像素为单位。 | DisplayObject | |
![]() | x : Number
表示 DisplayObject 实例相对于父级 DisplayObjectContainer 本地坐标的 x 坐标。 | DisplayObject | |
![]() | y : Number
表示 DisplayObject 实例相对于父级 DisplayObjectContainer 本地坐标的 y 坐标。 | DisplayObject | |
![]() | z : Number
表示 DisplayObject 实例相对于 3D 父容器沿 z 轴的 z 坐标位置。 | DisplayObject | |
| 方法 | 由以下参数定义 | ||
|---|---|---|---|
![]() |
将一个 DisplayObject 子实例添加到该 DisplayObjectContainer 实例中。 | DisplayObjectContainer | |
![]() |
将一个 DisplayObject 子实例添加到该 DisplayObjectContainer 实例中。 | DisplayObjectContainer | |
![]() | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。 | EventDispatcher | |
![]() |
表示安全限制是否会导致出现以下情况:在列表中忽略了使用指定 point 点调用 DisplayObjectContainer.getObjectsUnderPoint() 方法时返回的所有显示对象。 | DisplayObjectContainer | |
![]() |
确定指定显示对象是 DisplayObjectContainer 实例的子项还是该实例本身。 | DisplayObjectContainer | |
![]() |
将事件调度到事件流中。 | EventDispatcher | |
将 TextLine 的基础内容转储为 XML 字符串。 | TextLine | ||
自以下版本起不推荐使用: Flash Player 10.1现在不执行任何操作
此方法已否决且不起任何作用。 | TextLine | ||
获取指定索引处 atom 的双向级别。 | TextLine | ||
获取指定索引处与文本行相关的 atom 的范围。 | TextLine | ||
获取指定索引处沿基线测量的 atom 中心。 | TextLine | ||
获取指定索引处 atom 的图形;如果该 atom 是一个字符,则为 null。 | TextLine | ||
返回包含由 charIndex 参数指定的字符的 atom 的索引;如果该字符不构成行中的任何 atom,则返回 -1。 | TextLine | ||
返回由 x 和 y 参数指定的点处的 atom 的索引;如果该点处没有 atom,则返回 -1。 | TextLine | ||
获取指定索引处 atom 的文本块开始索引。 | TextLine | ||
获取指定索引处 atom 的文本块结束索引。 | TextLine | ||
获取指定索引处 atom 的旋转。 | TextLine | ||
表示文字边界是否在指定索引处 atom 的左侧出现。 | TextLine | ||
获取与 TextBlock.baselineZero 相关的指定基线的位置。 | TextLine | ||
![]() |
返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。 | DisplayObject | |
![]() |
返回位于指定索引处的子显示对象实例。 | DisplayObjectContainer | |
![]() |
返回具有指定名称的子显示对象。 | DisplayObjectContainer | |
![]() |
返回 DisplayObject 的 child 实例的索引位置。 | DisplayObjectContainer | |
返回行上其 mirror 属性与 mirror 参数指定的属性相匹配的第一个 TextLineMirrorRegion;如果没有匹配项,则为 null。 | TextLine | ||
![]() |
返回对象的数组,这些对象位于指定点下,并且是该 DisplayObjectContainer 实例的子项(或孙子项,依此类推)。 | DisplayObjectContainer | |
![]() |
返回一个矩形,该矩形根据 targetCoordinateSpace 参数定义的坐标系定义显示对象的边界,但不包括形状上的任何笔触。 | DisplayObject | |
![]() |
将 point 对象从舞台(全局)坐标转换为显示对象的(本地)坐标。 | DisplayObject | |
![]() |
将二维点从舞台(全局)坐标转换为三维显示对象的(本地)坐标。 | DisplayObject | |
![]() |
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。 | EventDispatcher | |
![]() |
表示对象是否已经定义了指定的属性。 | Object | |
![]() |
计算显示对象的边框,以确定它是否与 obj 显示对象的边框重叠或相交。 | DisplayObject | |
![]() |
计算显示对象,以确定它是否与 x 和 y 参数指定的点重叠或相交。 | DisplayObject | |
![]() |
表示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
将三维显示对象的(本地)坐标的三维点转换为舞台(全局)坐标中的二维点。 | DisplayObject | |
![]() |
将 point 对象从显示对象的(本地)坐标转换为舞台(全局)坐标。 | DisplayObject | |
![]() |
表示指定的属性是否存在、是否可枚举。 | Object | |
![]() |
从 DisplayObjectContainer 实例的子列表中删除指定的 child DisplayObject 实例。 | DisplayObjectContainer | |
![]() |
从 DisplayObjectContainer 的子列表中指定的 index 位置删除子 DisplayObject。 | DisplayObjectContainer | |
![]() |
从 DisplayObjectContainer 实例的子级列表中删除所有子 DisplayObject 实例。 | DisplayObjectContainer | |
![]() |
从 EventDispatcher 对象中删除侦听器。 | EventDispatcher | |
![]() |
显示虚拟键盘。 | InteractiveObject | |
![]() |
更改现有子项在显示对象容器中的位置。 | DisplayObjectContainer | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
对源起于此对象的所有 MovieClip 递归停止时间轴执行。 | DisplayObjectContainer | |
![]() |
交换两个指定子对象的 Z 轴顺序(从前到后顺序)。 | DisplayObjectContainer | |
![]() |
在子级列表中两个指定的索引位置,交换子对象的 Z 轴顺序(前后顺序)。 | DisplayObjectContainer | |
![]() |
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
![]() |
检查是否用此 EventDispatcher 对象或其任何祖代为指定事件类型注册了事件侦听器。 | EventDispatcher | |
| 常量 | 由以下参数定义 | ||
|---|---|---|---|
| MAX_LINE_WIDTH : int = 1000000 [静态]
文本行的最大请求宽度(以像素为单位)。 | TextLine | ||
ascent | 属性 |
atomCount | 属性 |
atomCount:int [只读] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
行中的 atom 数,即不可分割的元素数,其中包括空格和图形元素。
实现
public function get atomCount():int引发
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
descent | 属性 |
hasGraphicElement | 属性 |
hasTabs | 属性 |
mirrorRegions | 属性 |
nextLine | 属性 |
nextLine:flash.text.engine:TextLine [只读] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
TextBlock 中的下一个 TextLine;如果当前行是块中的最后一行或行的 validity 为 TextLineValidity.STATIC,则为 null。
实现
public function get nextLine():flash.text.engine:TextLine相关 API 元素
previousLine | 属性 |
previousLine:flash.text.engine:TextLine [只读] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
TextBlock 中的上一个 TextLine;如果行是块中的第一行或行的 validity 为 TextLineValidity.STATIC,则为 null。
实现
public function get previousLine():flash.text.engine:TextLine相关 API 元素
rawTextLength | 属性 |
specifiedWidth | 属性 |
textBlock | 属性 |
textBlock:flash.text.engine:TextBlock [只读] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
包含此文本行的 TextBlock;如果该行的 validity 为 TextLineValidity.STATIC,则为 null,表示已切断行与文本块之间的连接。
实现
public function get textBlock():flash.text.engine:TextBlock相关 API 元素
textBlockBeginIndex | 属性 |
textHeight | 属性 |
textWidth | 属性 |
textWidth:Number [只读] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
文本行的逻辑宽度,即文本引擎用于布置行的宽度。访问继承的 width 属性以获取所有绘制的像素的边框的实际宽度。
实现
public function get textWidth():Number相关 API 元素
示例 ( 如何使用本示例 )
specifiedWidth、textWidth 和 width 属性的值。跟踪输出结果为:
- specifiedWidth is: 500
- textWidth is: 268.9921875
- width is: 269
- specifiedWidth is: 500
- textWidth is: 267.52734375
- width is: 267.55
package {
import flash.display.Sprite;
import flash.text.engine.TextBlock;
import flash.text.engine.TextElement;
import flash.text.engine.TextLine;
import flash.text.engine.FontDescription;
import flash.text.engine.ElementFormat;
import flash.text.engine.FontPosture;
public class TextLine_textWidthExample extends Sprite {
public function TextLine_textWidthExample() {
var str:String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, ";
var yPos:Number = 20;
var fontDescription:FontDescription = new FontDescription();
var textBlock:TextBlock = new TextBlock();
fontDescription.fontPosture = FontPosture.NORMAL;
var format:ElementFormat = new ElementFormat(fontDescription, 12);
var textElement:TextElement = new TextElement(str, format);
textBlock.content = textElement;
createLine(textBlock, yPos);
var fontDescriptionItalic = fontDescription.clone();
fontDescriptionItalic.fontPosture = FontPosture.ITALIC;
var formatItalic = new ElementFormat(fontDescriptionItalic, 12);
textElement = new TextElement(str, formatItalic);
textBlock.content = textElement;
createLine(textBlock, yPos + 20);
}
private function createLine(textBlock:TextBlock, yPos:Number):void {
var textLine:TextLine = textBlock.createTextLine (null, 500);
trace("specifiedWidth is: " + textLine.specifiedWidth);
trace("textWidth is: " + textLine.textWidth);
trace("width is: " + textLine.width);
addChild(textLine);
textLine.x = 15;
textLine.y = yPos;
}
}
}
totalAscent | 属性 |
totalDescent | 属性 |
totalHeight | 属性 |
unjustifiedTextWidth | 属性 |
unjustifiedTextWidth:Number [只读] | 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
行未两端对齐时的宽度。对于未对齐的文本,此值与 textWidth 相同。对于对齐的文本,此值为未对齐时具有的长度,并且 textWidth 表示实际的行宽度。例如,当将以下字符串对齐并按照 500 的宽度提交给 TextBlock.createTextLine() 时,该字符串的实际宽度为 500,而未对齐的宽度为 268.9921875。
实现
public function get unjustifiedTextWidth():Number相关 API 元素
示例 ( 如何使用本示例 )
import flash.display.Sprite;
import flash.text.engine.TextBlock;
import flash.text.engine.TextElement;
import flash.text.engine.TextLine;
import flash.text.engine.FontDescription;
import flash.text.engine.ElementFormat;
import flash.text.engine.SpaceJustifier;
import flash.text.engine.LineJustification;
var str:String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, ";
var fontDescription:FontDescription = new FontDescription();
var textBlock:TextBlock = new TextBlock();
var format:ElementFormat = new ElementFormat(fontDescription, 12);
var textElement:TextElement = new TextElement(str, format);
textBlock.content = textElement;
var spaceJustifier:SpaceJustifier = new SpaceJustifier("en", LineJustification.ALL_INCLUDING_LAST);
textBlock.textJustifier = spaceJustifier;
var textLine:TextLine = textBlock.createTextLine(null, 500);
textLine.y = 20;
addChild(textLine);
trace("textWidth value is: " + textLine.textWidth); // 500.00244140625
trace("unjustifiedTextWidth is: " + textLine.unjustifiedTextWidth); // 268.9921875
userData | 属性 |
public var userData:*| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
为应用程序提供一种将任意数据与文本行相关联的方法。
validity | 属性 |
validity:String| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
指定文本行的当前有效性。此属性的值包括在 TextLineValidity 类的成员中。用于设置此属性的规则如下:
如果将 validity 设置为非 TextLineValidity 成员的任何字符串,则会将行视为 USER_INVALID。USER_INVALID 是一个抽象概念,在此处用于表示任何这样的值。
修改 TextBlock 的内容后,Flash 运行时标记影响文本行、上一行和所有下列 INVALID 行。如果所做更改允许前一行吸收最初位于第一个受影响行上的部分内容,则必须将前一行标记为 INVALID。
新断开的行始终为 VALID。Flash 运行时可能更改从 VALID 到 POSSIBLY_INVALID 或 INVALID 的行。如果换行符相匹配,则播放器代码可能会将 POSSIBLY_INVALID 行更改为 VALID,否则,将此行更改为 INVALID。
应用程序代码可将 VALID 行标记为 INVALID 或 USER_INVALID 并可将 USER_INVALID 行标记为 VALID。应用程序代码无法标记行 POSSIBLY_INVALID。
应用程序代码可标记任何行 STATIC。这样做会使 block 成员变为 null。如果 STATIC 文本行中的图形元素是最初派生 STATIC 文本行的文本块中断开的新文本行的一部分,则将删除这些图形元素并重定父级。
实现
public function get validity():String public function set validity(value:String):void引发
ArgumentError — 如果当前值为 TextLineValidity.STATIC。
| |
ArgumentError — 如果当前值为 TextLineValidity.INVALID 并且新值为 TextValidity.STATIC 之外的任何值。
| |
ArgumentError — 如果当前值为 TextLineValidity.POSSIBLY_INVALID 并且新值为 TextLineValidity.VALID。
| |
ArgumentError — 如果新值为 TextLineValidity.POSSIBLY_INVALID。
|
相关 API 元素
dump | () | 方法 |
public function dump():String| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5 |
将 TextLine 的基础内容转储为 XML 字符串。这在自动测试过程中很有用,并包括文本、格式和布局信息。
以下内容描述了输出:
[LINE] <line ascent=[Number] descent=[Number] rotation=[int]> <elements> [0-N ELEMENT] </elements> <clusters> [0-N CLUSTER] </clusters> </line> [ELEMENT] <glyph isEmbedded=[Boolean] fontName=[String] isBold=[Boolean] isItalic=[Boolean] gid=[int] pointSize=[Number] x=[Number] y=[Number] rotation=[int]/> or <graphic child=[int] x=[Number] y=[Number] rotation=[int]/> or <embeddedRun x=[Number] y=[Number]> [LINE] </embeddedRun> [CLUSTER] <cluster xLeft=[Number] xCenter=[Number] xRight=[Number] cursorOnLeft=[Boolean] cursorOnRight=[Boolean] wordBoundaryOnLeft=[Boolean] wordBoundaryOnRight=[Boolean]/>
注意:将来可能更改此方法中输出的内容和格式。Adobe 不保证此方法的向后兼容性。
返回String |
相关 API 元素
flushAtomData | () | 方法 |
public function flushAtomData():void| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
此方法已否决且不起任何作用。atom 数据已压缩,并不是管理内存效率中的因素。
相关 API 元素
getAtomBidiLevel | () | 方法 |
public function getAtomBidiLevel(atomIndex:int):int| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取指定索引处 atom 的双向级别。由 TextBlock.bidiLevel 和构成行的字符的 Unicode 双向属性共同确定。
例如,如果您使用一些希伯来语文字来作为文本块的开头,并将 TextBlock.bidiLevel 设置为 1,则将确立从右到左的默认文本顺序。如果您在文本中引用了一段英文(从左到右),则这些英文的 AtomBidiLevel 为 2。如果英文文字中包含少量阿拉伯文字(从右到左),则这些阿拉伯文字的 AtomBidiLevel 将为 3。如果阿拉伯文字中存在一个数字(从左到右),则该数字的 AtomBidiLevel 设置为 4。无论 atom 在哪一行中结束,希伯来语 atom 为 AtomBidiLevel 1,英语 atom 为 AtomBidiLevel 2,阿拉伯语 atom 为 AtomBidiLevel 3,数字 atom 为 AtomBidiLevel 4。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
int — atomIndex 处的 atom 的双向级别。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
相关 API 元素
getAtomBounds | () | 方法 |
public function getAtomBounds(atomIndex:int):Rectangle| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取指定索引处与文本行相关的 atom 的范围。指定的 atom 的范围由其在行中的水平位置 (x)、垂直位置 (y)、宽度 (w) 和高度 (h) 构成。所有值均以像素为单位。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
Rectangle — atomIndex 处 atom 的范围。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getAtomCenter | () | 方法 |
public function getAtomCenter(atomIndex:int):Number| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取指定索引处沿基线测量的 atom 中心。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
Number — atomIndex 处 atom 的中心。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getAtomGraphic | () | 方法 |
public function getAtomGraphic(atomIndex:int):DisplayObject| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取指定索引处 atom 的图形;如果该 atom 是一个字符,则为 null。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
DisplayObject — atomIndex 处 atom 的图形。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getAtomIndexAtCharIndex | () | 方法 |
public function getAtomIndexAtCharIndex(charIndex:int):int| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
返回包含由 charIndex 参数指定的字符的 atom 的索引;如果该字符不构成行中的任何 atom,则返回 -1。charIndex 相对于包含该行的文本块的全部内容。
参数
charIndex:int — 从零开始的字符索引值(例如,第一个字符的索引值是 0,第二个字符的索引值是 1,依此类推)。
|
int — 包含 charIndex 处字符的 atom 的索引。如果该字符不构成行中的任何 atom,则返回 -1。
|
引发
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getAtomIndexAtPoint | () | 方法 |
public function getAtomIndexAtPoint(stageX:Number, stageY:Number):int| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
返回由 x 和 y 参数指定的点处的 atom 的索引;如果该点处没有 atom ,则返回 -1。
此方法采用全局坐标,以便您可以轻松地将其与 MouseEvent.stageX 和 MouseEvent.stageY 属性一起使用。
参数
stageX:Number — 要测试的点的全局 x 坐标。
| |
stageY:Number — 要测试的点的全局 y 坐标。
|
int — 点下方 atom 的索引。如果点不在任何 atom 上方,则返回 -1。
|
引发
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getAtomTextBlockBeginIndex | () | 方法 |
public function getAtomTextBlockBeginIndex(atomIndex:int):int| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取指定索引处 atom 的文本块开始索引。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
int — atomIndex 处 atom 的文本块开始索引。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getAtomTextBlockEndIndex | () | 方法 |
public function getAtomTextBlockEndIndex(atomIndex:int):int| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取指定索引处 atom 的文本块结束索引。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
int — atomIndex 处 atom 的文本块结束索引。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getAtomTextRotation | () | 方法 |
public function getAtomTextRotation(atomIndex:int):String| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取指定索引处 atom 的旋转。对此属性使用 TextRotation 常量。atom 的旋转是元素和行的累积旋转。其主要用途是在与 TextLine 进行交互时设置尖号(光标)的方向。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
String — atomIndex 处 atom 的旋转。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
相关 API 元素
getAtomWordBoundaryOnLeft | () | 方法 |
public function getAtomWordBoundaryOnLeft(atomIndex:int):Boolean| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
表示文字边界是否在指定索引处 atom 的左侧出现。文字边界由构成行的字符的 Unicode 属性决定。
参数
atomIndex:int — 从零开始的 atom 索引值(例如,第一个 atom 的索引值是 0,第二个 atom 的索引值是 1,依此类推)。
|
Boolean — 一个布尔值,表示文字边界是否在 atomIndex 处 atom 的左侧出现。
|
引发
RangeError — 指定的 atom 索引超出范围。
| |
IllegalOperationError — 行的 validity 为 TextLineValidity.STATIC。
|
getBaselinePosition | () | 方法 |
public function getBaselinePosition(baseline:String):Number| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
获取与 TextBlock.baselineZero 相关的指定基线的位置。
参数
baseline:String — 要检索其位置的基线。使用 TextBaseline 值。
|
Number — 与 TextBlock.baselineZero 相关的指定基线的位置。
|
引发
ArgumentError — 如果指定的 baseline 不是 TextBaseline 的成员。
|
相关 API 元素
getMirrorRegion | () | 方法 |
public function getMirrorRegion(mirror:EventDispatcher):flash.text.engine:TextLineMirrorRegion| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
返回行上其 mirror 属性与 mirror 参数指定的属性相匹配的第一个 TextLineMirrorRegion;如果没有匹配项,则为 null。
即使是一个 TextElement 也可以在一个或多个文本行上生成多个 TextLineMirrorRegion 对象,具体取决于双向级别和换行设置。nextRegion 和 previousRegion 属性链接从一个文本元素生成的所有镜像区域。
参数
mirror:EventDispatcher — 要搜索的 EventDispatcher 镜像对象。
|
flash.text.engine:TextLineMirrorRegion — 行上其 mirror 属性与指定值相匹配的第一个 TextLineMirrorRegion;如果没有匹配项,则为 null。
|
相关 API 元素
MAX_LINE_WIDTH | 常量 |
public static const MAX_LINE_WIDTH:int = 1000000| 语言版本: | ActionScript 3.0 |
| 运行时版本: | Flash Player 10, AIR 1.5, Flash Lite 4 |
文本行的最大请求宽度(以像素为单位)。如果您没有指定值,则 TextBlock.createTextLine() 方法使用此常量作为 width 参数的默认值。
相关 API 元素
getAtomBounds() 为每个原子加边框,显示了各文本行并遍历了文本块中的原子。
- 将 NumericStepper 组件添加到库中。
- 将该代码作为 TextLineExample.as 另存到 FLA 文件所在的同一目录中。
- 将 FLA 的“属性”窗口中的“类”设置为“TextLineExample”。
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;
import flash.text.engine.FontDescription;
import flash.text.engine.FontPosture;
import flash.text.engine.FontWeight;
import fl.controls.NumericStepper;
import flash.events.Event;
import flash.geom.Rectangle;
public class TextLineExample extends Sprite {
private var atomStepper:NumericStepper = new NumericStepper();
private var atomDataContainer:Sprite;
private var fontDescriptionItalic:FontDescription = new FontDescription("Arial", FontWeight.NORMAL, FontPosture.ITALIC);
private var fontDescriptionNormal:FontDescription = new FontDescription("Arial", FontWeight.NORMAL , FontPosture.NORMAL);
private var textBlock:TextBlock = new TextBlock();
private var textLine:TextLine;
public function TextLineExample():void {
var myText:String = "I am a TextElement, created from a String and assigned " +
"to the content property of a TextBlock. From the text block, " +
"the createTextLine() method created these lines, 300 pixels wide, " +
"for display." ;
atomStepper.minimum = 0;
atomStepper.value = 0;
atomStepper.width = 50;
addChild(atomStepper);
atomStepper.x = 20;
atomStepper.y = 120;
atomStepper.addEventListener(Event.CHANGE, nsChange);
var directions:String = "Click up / down arrows to frame atoms in text block above.";
var formatItalic:ElementFormat = new ElementFormat(fontDescriptionItalic);
formatItalic.fontSize = 12;
var textElement1:TextElement = new TextElement(directions, formatItalic);
textBlock.content = textElement1;
createLines(textBlock, 15, 160, 400, this);
var formatNormal:ElementFormat = new ElementFormat(fontDescriptionNormal);
formatNormal.fontSize = 16;
var textElement2:TextElement = new TextElement(myText, formatNormal);
textBlock.content = textElement2;
createLines(textBlock, 15.0, 20.0, 300, this);
textLine = textBlock.firstLine;
atomStepper.maximum = textLine.atomCount - 1;
showAtom(textLine, 0);
}
private function nsChange(event:Event):void
{
removeAtom(textLine);
if (atomStepper.value == textLine.atomCount - 1)
{
if(textLine != textBlock.lastLine)
{
textLine = textLine.nextLine;
atomStepper.maximum = textLine.atomCount - 1;
atomStepper.value = 0;
}
}
showAtom(textLine, atomStepper.value);
}
private function createLines(textBlock, startX, startY, width, container)
{
var textLine:TextLine = textBlock.createTextLine (null, width);
while (textLine)
{
textLine.x = startX;
textLine.y = startY;
startY += textLine.height + 2;
container.addChild(textLine);
textLine = textBlock.createTextLine (textLine, width);
}
}
private function showAtom(textLine, i):void
{
var box:Sprite = new Sprite();
var mcGraphics = box.graphics;
var bounds:Rectangle = textLine.getAtomBounds(i);
mcGraphics.lineStyle(1, 0xFF0000, 1.0);
mcGraphics.drawRect(bounds.left, bounds.top, bounds.width, bounds.height);
textLine.userData = textLine.addChild(box);
displayAtomData(textLine,i);
}
private function displayAtomData(textLine, i)
{
if(atomDataContainer != null)
removeChild(atomDataContainer);
atomDataContainer=new Sprite();
var format = new ElementFormat(fontDescriptionNormal);
format.color = 0x00000FF;
var n:int = 0;
var nxtY:Number = 0;
var atomInfo:String = "value of getAtomBidiLevel() is: " + textLine.getAtomBidiLevel(i)+"\n"
+"value of getAtomCenter() is: " + textLine.getAtomCenter(i)+"\n"
+"value of getAtomIndexAtCharIndex() is: " + textLine.getAtomIndexAtCharIndex(i)+"\n"
+"value of getAtomTextBlockBeginIndex() is: " + textLine.getAtomTextBlockBeginIndex(i)+"\n"
+"value of getAtomTextBlockEndIndex() is: " + textLine.getAtomTextBlockEndIndex(i)+"\n"
+"value of getAtomTextRotation() is: " + textLine.getAtomTextRotation(i)+"\n";
var atomtextBlock:TextBlock = new TextBlock();
var textElement3:TextElement = new TextElement(atomInfo, format);
atomtextBlock.content = textElement3;
createLines(atomtextBlock,20,200,500, atomDataContainer)
addChild(atomDataContainer);
}
private function removeAtom(textLine):void
{
textLine.removeChild(textLine.userData);
}
}
}
Tue Jun 12 2018, 11:04 AM Z
隐藏继承的公共属性
显示继承的公共属性