flash.text
public class TextField
继承TextField Inheritance InteractiveObject Inheritance DisplayObject Inheritance EventDispatcher Inheritance Object

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

TextField 类用于创建显示对象以显示和输入文本。 SWF 文件中的所有动态文本字段和输入文本字段都是 TextField 类的实例。 可以在属性检查器中为文本字段指定实例名称,并且可以在 ActionScript 中使用 TextField 类的方法和属性对文本字段进行操作。 TextField 的实例名称显示在“影片管理器”中及“动作”面板的“插入目标路径”对话框中。

若要动态创建文本字段,请使用 TextField() 构造函数。

TextField 类的方法允许您设置、选择并操作在创作过程中或运行时创建的动态或输入文本字段中的文本。

ActionScript 提供了多种在运行时设置文本格式的方法。 TextFormat 类允许您设置 TextField 对象的字符和段落格式。 您可以使用 TextField.styleSheet 属性和 StyleSheet 类来对文本字段应用层叠样式表 (CSS) 样式。 您可以使用 CSS 设置内置 HTML 标签的样式、定义新的格式设置标签或应用样式。 您可以将 HTML 格式的文本(该文本可以选择使用 CSS 样式)直接分配给文本字段。 分配给文本字段的 HTML 文本可以包含嵌入的媒体(影片剪辑、SWF 文件、GIF 文件、PNG 文件和 JPEG 文件)。 文本在嵌入的媒体旁自动换行,这与 Web 浏览器的文本在 HTML 文档中嵌入的媒体旁换行非常类似。

Flash Player 还支持部分 HTML 标签,可以使用这些 HTML 标签设置文本格式。 要查看受支持 HTML 标签的列表,请参阅对 htmlText 属性的描述。

查看示例

另请参见

flash.text.TextFormat
flash.text.StyleSheet
核心显示类
处理文本的基础知识


公共 属性
 属性定义方
 InheritedaccessibilityProperties : AccessibilityProperties
此显示对象的当前辅助功能选项。
DisplayObject
 Inheritedalpha : Number
指示指定对象的 Alpha 透明度值。
DisplayObject
  alwaysShowSelection : Boolean
如果设置为 true 且文本字段没有焦点,Flash Player 将以灰色突出显示文本字段中的所选内容。
TextField
  antiAliasType : String
用于此文本字段的消除锯齿类型。
TextField
  autoSize : String
控制文本字段的自动大小调整和对齐。
TextField
  background : Boolean
指定文本字段是否具有背景填充。
TextField
  backgroundColor : uint
文本字段背景的颜色。
TextField
 InheritedblendMode : String
BlendMode 类中的一个值,用于指定要使用的混合模式。
DisplayObject
  border : Boolean
指定文本字段是否具有边框。
TextField
  borderColor : uint
文本字段边框的颜色。
TextField
  bottomScrollV : int
[read-only] 一个整数(从 1 开始的索引),指示指定文本字段中当前可以看到的最后一行。
TextField
 InheritedcacheAsBitmap : Boolean
如果设置为 true,则 Flash Player 将缓存显示对象的内部位图表示形式。
DisplayObject
  caretIndex : int
[read-only] 插入点(尖号)位置的索引。
TextField
  condenseWhite : Boolean
一个布尔值,它指定是否应删除具有 HTML 文本的文本字段中的额外空白(空格、换行符等)。
TextField
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
 InheritedcontextMenu : ContextMenu
指定与此对象相关联的上下文菜单。
InteractiveObject
  defaultTextFormat : TextFormat
指定应用于新插入文本(例如,使用 replaceSelectedText() 方法插入的文本或用户输入的文本)的格式。
TextField
  displayAsPassword : Boolean
指定文本字段是否是密码文本字段。
TextField
 InheriteddoubleClickEnabled : Boolean
指定此对象是否接收 doubleClick 事件。
InteractiveObject
  embedFonts : Boolean
指定是否使用嵌入字体轮廓进行呈现。
TextField
 Inheritedfilters : Array
包含当前与显示对象关联的每个滤镜对象的索引数组。
DisplayObject
 InheritedfocusRect : Object
指定此对象是否显示焦点矩形。
InteractiveObject
  gridFitType : String
用于此文本字段的网格固定类型。
TextField
 Inheritedheight : Number
指示显示对象的高度,以像素为单位。
DisplayObject
  htmlText : String
包含文本字段内容的 HTML 表示形式。
TextField
  length : int
[read-only] 文本字段中的字符数。
TextField
 InheritedloaderInfo : LoaderInfo
[read-only] 返回一个 LoaderInfo 对象,其中包含加载此显示对象所属的文件的相关信息。
DisplayObject
 Inheritedmask : DisplayObject
调用显示对象被指定的 mask 对象遮罩。
DisplayObject
  maxChars : int
文本字段中最多可包含的字符数(即用户输入的字符数)。
TextField
  maxScrollH : int
[read-only] scrollH 的最大值。
TextField
  maxScrollV : int
[read-only] scrollV 的最大值。
TextField
 InheritedmouseEnabled : Boolean
指定此对象是否接收鼠标消息。
InteractiveObject
  mouseWheelEnabled : Boolean
一个布尔值,指示当用户单击某个文本字段且用户滚动鼠标滚轮时,Flash Player 是否应自动滚动多行文本字段。
TextField
 InheritedmouseX : Number
[read-only] 指示鼠标位置的 x 坐标,以像素为单位。
DisplayObject
 InheritedmouseY : Number
[read-only] 指示鼠标位置的 y 坐标,以像素为单位。
DisplayObject
  multiline : Boolean
指示文本字段是否为多行文本字段。
TextField
 Inheritedname : String
指示 DisplayObject 的实例名称。
DisplayObject
  numLines : int
[read-only] 定义多行文本字段中的文本行数。
TextField
 InheritedopaqueBackground : Object
指定显示对象是否由于具有某种背景颜色而不透明。
DisplayObject
 Inheritedparent : DisplayObjectContainer
[read-only] 指示包含此显示对象的 DisplayObjectContainer 对象。
DisplayObject
 Inheritedprototype : Object
[static] 对类或函数对象的原型对象的引用。
Object
  restrict : String
指示用户可输入到文本字段中的字符集。
TextField
 Inheritedroot : DisplayObject
[read-only] 对于加载的 SWF 文件中的显示对象,root 属性是此 SWF 文件所表示的显示列表树结构部分中的顶级显示对象。
DisplayObject
 Inheritedrotation : Number
指示 DisplayObject 实例距其原始方向的旋转程度,以度为单位。
DisplayObject
 Inheritedscale9Grid : Rectangle
当前有效的缩放网格。
DisplayObject
 InheritedscaleX : Number
指示从注册点开始应用的对象的水平缩放比例(百分比)。
DisplayObject
 InheritedscaleY : Number
指示从对象注册点开始应用的对象的垂直缩放比例(百分比)。
DisplayObject
  scrollH : int
当前水平滚动位置。
TextField
 InheritedscrollRect : Rectangle
显示对象的滚动矩形范围。
DisplayObject
  scrollV : int
文本在文本字段中的垂直位置。
TextField
  selectable : Boolean
一个布尔值,指示文本字段是否可选。
TextField
  selectionBeginIndex : int
[read-only] 当前所选内容中第一个字符从零开始的字符索引值。
TextField
  selectionEndIndex : int
[read-only] 当前所选内容中最后一个字符从零开始的字符索引值。
TextField
  sharpness : Number
此文本字段中字型边缘的清晰度。
TextField
 Inheritedstage : Stage
[read-only] 显示对象的舞台。
DisplayObject
  styleSheet : StyleSheet
将样式表附加到文本字段。
TextField
 InheritedtabEnabled : Boolean
指定此对象是否遵循 Tab 键顺序。
InteractiveObject
 InheritedtabIndex : int
指定 SWF 文件中的对象按 Tab 键顺序排列。
InteractiveObject
  text : String
作为文本字段中当前文本的字符串。
TextField
  textColor : uint
文本字段中文本的颜色(采用十六进制格式)。
TextField
  textHeight : Number
[read-only] 文本的高度,以像素为单位。
TextField
  textWidth : Number
[read-only] 文本的宽度,以像素为单位。
TextField
  thickness : Number
此文本字段中字型边缘的粗细。
TextField
 Inheritedtransform : Transform
一个对象,具有与显示对象的矩阵、颜色转换和像素范围有关的属性。
DisplayObject
  type : String
文本字段的类型。
TextField
  useRichTextClipboard : Boolean
指定在复制和粘贴文本时是否同时复制和粘贴其格式。
TextField
 Inheritedvisible : Boolean
显示对象是否可见。
DisplayObject
 Inheritedwidth : Number
指示显示对象的宽度,以像素为单位。
DisplayObject
  wordWrap : Boolean
一个布尔值,指示文本字段是否自动换行。
TextField
 Inheritedx : Number
指示 DisplayObject 实例相对于父级 DisplayObjectContainer 本地坐标的 x 坐标。
DisplayObject
 Inheritedy : Number
指示 DisplayObject 实例相对于父级 DisplayObjectContainer 本地坐标的 y 坐标。
DisplayObject
公共 方法
 方法定义方
  
创建新的 TextField 实例。
TextField
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
  
将 newText 参数指定的字符串追加到文本字段的文本的末尾。
TextField
 Inherited
将事件调度到事件流中。
EventDispatcher
 Inherited
getBounds(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。
DisplayObject
  
返回一个矩形,该矩形是字符的边框。
TextField
  
在 x 和 y 参数指定的位置返回从零开始的字符索引值。
TextField
  
如果给定一个字符索引,则返回同一段落中第一个字符的索引。
TextField
  
返回给定 id 或已使用 标签添加到 HTML 格式文本字段中的图像或 SWF 文件的 DisplayObject 引用。
TextField
  
在 x 和 y 参数指定的位置返回从零开始的行索引值。
TextField
  
返回 charIndex 参数指定的字符所在的行的索引值(从零开始)。
TextField
  
getLineLength(lineIndex:int):int
返回特定文本行中的字符数。
TextField
  
返回给定文本行的度量信息。
TextField
  
getLineOffset(lineIndex:int):int
返回 lineIndex 参数指定的行中第一个字符的字符索引。
TextField
  
getLineText(lineIndex:int):String
返回 lineIndex 参数指定的行的文本。
TextField
  
如果给定一个字符索引,则返回包含给定字符的段落的长度。
TextField
 Inherited
getRect(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形根据 targetCoordinateSpace 参数定义的坐标系定义显示对象的边界,但不包括形状上的任何笔触。
DisplayObject
  
getTextFormat(beginIndex:int = -1, endIndex:int = -1):TextFormat
返回 TextFormat 对象,其中包含 beginIndex 和 endIndex 参数指定的文本范围的格式信息。
TextField
 Inherited
将 point 对象从舞台(全局)坐标转换为显示对象的(本地)坐标。
DisplayObject
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
指示对象是否已经定义了指定的属性。
Object
 Inherited
计算显示对象,以确定它是否与 obj 显示对象重叠或相交。
DisplayObject
 Inherited
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
计算显示对象,以确定它是否与 x 和 y 参数指定的点重叠或相交。
DisplayObject
 Inherited
指示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
 Inherited
将 point 对象从显示对象的(本地)坐标转换为舞台(全局)坐标。
DisplayObject
 Inherited
指示指定的属性是否存在、是否可枚举。
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
  
使用 value 参数的内容替换当前所选内容。
TextField
  
replaceText(beginIndex:int, endIndex:int, newText:String):void
使用 newText 参数的内容替换 beginIndex 和 endIndex 参数指定的字符范围。
TextField
 Inherited
设置循环操作动态属性的可用性。
Object
  
setSelection(beginIndex:int, endIndex:int):void
将第一个字符和最后一个字符的索引值(使用 beginIndex 和 endIndex 参数指定)指定的文本设置为所选内容。
TextField
  
setTextFormat(format:TextFormat, beginIndex:int = -1, endIndex:int = -1):void
将 format 参数指定的文本格式应用于文本字段中的指定文本。
TextField
 Inherited
返回指定对象的字符串表示形式。
Object
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何始祖为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件摘要定义方
 Inherited Flash Player 获得操作系统焦点并变为活动状态时调度。EventDispatcher
 Inherited 将显示对象添加到显示列表中时调度。DisplayObject
 Inherited 在将显示对象直接添加到舞台显示列表或将包含显示对象的子树添加至舞台显示列表中时调度。DisplayObject
   修改控件的值后调度。TextField
 Inherited 用户在同一 InteractiveObject 上按下并释放用户指针设备的主按钮时调度。InteractiveObject
 Inherited Flash Player 失去操作系统焦点并变为非活动状态时调度。EventDispatcher
 Inherited 如果 InteractiveObject 的 doubleClickEnabled 标志设置为 true,当用户在该对象上快速连续按下两次并释放指针设备的主按钮时调度。InteractiveObject
 Inherited 播放头进入新帧时调度。DisplayObject
 Inherited 显示对象获得焦点后调度。InteractiveObject
 Inherited 显示对象失去焦点后调度。InteractiveObject
 Inherited 用户按下某个键时调度。InteractiveObject
 Inherited 用户尝试使用键盘导航更改焦点时调度。InteractiveObject
 Inherited 用户释放某个键时调度。InteractiveObject
   当用户单击启用 HTML 的文本字段中的超链接(其中的 URL 以“event:”开头)时调度。TextField
 Inherited 在 Flash Player 窗口中,用户在 InteractiveObject 实例上按下指针设备按钮时调度。InteractiveObject
 Inherited 用户尝试使用指针设备更改焦点时调度。InteractiveObject
 Inherited 用户移动 InteractiveObject 上的指针设备时调度。InteractiveObject
 Inherited 用户将指针设备从 InteractiveObject 实例上移开时调度。InteractiveObject
 Inherited 在 Flash Player 窗口中,用户将指针设备移动到 InteractiveObject 实例上时调度。InteractiveObject
 Inherited 在 Flash Player 窗口中,用户在 InteractiveObject 实例上释放指针设备按钮时调度。InteractiveObject
 Inherited 在 Flash Player 窗口中,鼠标滚轮滚动到 InteractiveObject 实例上时调度。InteractiveObject
 Inherited 将要从显示列表中删除显示对象时调度。DisplayObject
 Inherited 在从显示列表中直接删除显示对象或删除包含显示对象的子树时调度。DisplayObject
 Inherited 将要更新和呈现显示列表时调度。DisplayObject
 Inherited 用户将指针设备从 InteractiveObject 实例上移开时调度。InteractiveObject
 Inherited 用户将指针设备移动到 InteractiveObject 实例上时调度。InteractiveObject
   用户滚动后由 TextField 对象调度。TextField
 Inherited 对象的 tabChildren 标志值发生更改时调度。InteractiveObject
 Inherited 对象的 tabEnabled 标志发生更改时调度。InteractiveObject
 Inherited 对象的 tabIndex 属性值发生更改时调度。InteractiveObject
   用户输入一个或多个文本字符时,Flash Player 将调度 textInput 事件。TextField
属性详细信息
alwaysShowSelection属性
alwaysShowSelection:Boolean  [read-write]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

如果设置为 true 且文本字段没有焦点,Flash Player 将以