適用於 Adobe® Flash® Platform 的 ActionScript® 3.0 參考
首頁  |  隱藏套件和類別清單 |  套件  |  類別  |  新增內容  |  索引  |  附錄  |  為什麼顯示英文?
篩選: AIR 30.0 和更早版本, Flash Player 30.0 和更早版本, Flash Lite 4
Flex 4.6 和更早版本, Flash Pro CS6 和更早版本
隱藏篩選
flash.text 

TextField  - AS3

套件x

最上層
adobe.utils
air.desktop
air.net
air.update
air.update.events
coldfusion.air
coldfusion.air.errors
coldfusion.air.events
coldfusion.service
coldfusion.service.events
coldfusion.service.mxml
com.adobe.acm.solutions.authoring.domain.extensions
com.adobe.acm.solutions.ccr.domain.extensions
com.adobe.consulting.pst.vo
com.adobe.dct.component
com.adobe.dct.component.datadictionary
com.adobe.dct.component.datadictionaryElement
com.adobe.dct.component.dataElementsPanel
com.adobe.dct.component.toolbars
com.adobe.dct.event
com.adobe.dct.exp
com.adobe.dct.model
com.adobe.dct.service
com.adobe.dct.service.provider
com.adobe.dct.transfer
com.adobe.dct.util
com.adobe.dct.view
com.adobe.ep.taskmanagement.domain
com.adobe.ep.taskmanagement.event
com.adobe.ep.taskmanagement.filter
com.adobe.ep.taskmanagement.services
com.adobe.ep.taskmanagement.util
com.adobe.ep.ux.attachmentlist.component
com.adobe.ep.ux.attachmentlist.domain
com.adobe.ep.ux.attachmentlist.domain.events
com.adobe.ep.ux.attachmentlist.domain.renderers
com.adobe.ep.ux.attachmentlist.skin
com.adobe.ep.ux.attachmentlist.skin.renderers
com.adobe.ep.ux.content.event
com.adobe.ep.ux.content.factory
com.adobe.ep.ux.content.handlers
com.adobe.ep.ux.content.managers
com.adobe.ep.ux.content.model.asset
com.adobe.ep.ux.content.model.preview
com.adobe.ep.ux.content.model.relation
com.adobe.ep.ux.content.model.search
com.adobe.ep.ux.content.model.toolbar
com.adobe.ep.ux.content.search
com.adobe.ep.ux.content.services
com.adobe.ep.ux.content.services.load
com.adobe.ep.ux.content.services.permissions
com.adobe.ep.ux.content.services.preview
com.adobe.ep.ux.content.services.providers
com.adobe.ep.ux.content.services.query
com.adobe.ep.ux.content.services.relationships
com.adobe.ep.ux.content.services.search.lccontent
com.adobe.ep.ux.content.services.version
com.adobe.ep.ux.content.view
com.adobe.ep.ux.content.view.components.activate
com.adobe.ep.ux.content.view.components.grid
com.adobe.ep.ux.content.view.components.grid.hover
com.adobe.ep.ux.content.view.components.grid.hover.component
com.adobe.ep.ux.content.view.components.grid.renderers
com.adobe.ep.ux.content.view.components.relationships
com.adobe.ep.ux.content.view.components.review
com.adobe.ep.ux.content.view.components.search.renderers
com.adobe.ep.ux.content.view.components.searchpod
com.adobe.ep.ux.content.view.components.toolbar
com.adobe.ep.ux.content.view.components.toolbar.controlRenderers
com.adobe.ep.ux.content.view.components.version
com.adobe.ep.ux.documentsubmit.component
com.adobe.ep.ux.documentsubmit.domain
com.adobe.ep.ux.documentsubmit.skin
com.adobe.ep.ux.taskaction.component
com.adobe.ep.ux.taskaction.domain
com.adobe.ep.ux.taskaction.domain.events
com.adobe.ep.ux.taskaction.skin
com.adobe.ep.ux.taskdetails.component
com.adobe.ep.ux.taskdetails.domain
com.adobe.ep.ux.taskdetails.skin
com.adobe.ep.ux.tasklist.component
com.adobe.ep.ux.tasklist.domain
com.adobe.ep.ux.tasklist.skin
com.adobe.ep.ux.webdocumentviewer.domain
com.adobe.exm.expression
com.adobe.exm.expression.error
com.adobe.exm.expression.event
com.adobe.exm.expression.impl
com.adobe.fiber.runtime.lib
com.adobe.fiber.services
com.adobe.fiber.services.wrapper
com.adobe.fiber.styles
com.adobe.fiber.util
com.adobe.fiber.valueobjects
com.adobe.gravity.binding
com.adobe.gravity.context
com.adobe.gravity.flex.bundleloader
com.adobe.gravity.flex.progress
com.adobe.gravity.flex.serviceloader
com.adobe.gravity.framework
com.adobe.gravity.init
com.adobe.gravity.service.bundleloader
com.adobe.gravity.service.logging
com.adobe.gravity.service.manifest
com.adobe.gravity.service.progress
com.adobe.gravity.tracker
com.adobe.gravity.ui
com.adobe.gravity.utility
com.adobe.gravity.utility.async
com.adobe.gravity.utility.error
com.adobe.gravity.utility.events
com.adobe.gravity.utility.factory
com.adobe.gravity.utility.flex.async
com.adobe.gravity.utility.logging
com.adobe.gravity.utility.message
com.adobe.gravity.utility.sequence
com.adobe.gravity.utility.url
com.adobe.guides.control
com.adobe.guides.domain
com.adobe.guides.i18n
com.adobe.guides.spark.components.skins
com.adobe.guides.spark.components.skins.mx
com.adobe.guides.spark.headers.components
com.adobe.guides.spark.headers.skins
com.adobe.guides.spark.layouts.components
com.adobe.guides.spark.layouts.skins
com.adobe.guides.spark.navigators.components
com.adobe.guides.spark.navigators.renderers
com.adobe.guides.spark.navigators.skins
com.adobe.guides.spark.util
com.adobe.guides.spark.wrappers.components
com.adobe.guides.spark.wrappers.skins
com.adobe.guides.submit
com.adobe.icc.dc.domain
com.adobe.icc.dc.domain.factory
com.adobe.icc.editors.events
com.adobe.icc.editors.handlers
com.adobe.icc.editors.managers
com.adobe.icc.editors.model
com.adobe.icc.editors.model.config
com.adobe.icc.editors.model.el
com.adobe.icc.editors.model.el.operands
com.adobe.icc.editors.model.el.operators
com.adobe.icc.enum
com.adobe.icc.external.dc
com.adobe.icc.obj
com.adobe.icc.services
com.adobe.icc.services.category
com.adobe.icc.services.config
com.adobe.icc.services.download
com.adobe.icc.services.export
com.adobe.icc.services.external
com.adobe.icc.services.formbridge
com.adobe.icc.services.fragmentlayout
com.adobe.icc.services.layout
com.adobe.icc.services.letter
com.adobe.icc.services.locator
com.adobe.icc.services.module
com.adobe.icc.services.render
com.adobe.icc.services.submit
com.adobe.icc.services.user
com.adobe.icc.token
com.adobe.icc.vo
com.adobe.icc.vo.render
com.adobe.icomm.assetplacement.controller
com.adobe.icomm.assetplacement.controller.utils
com.adobe.icomm.assetplacement.data
com.adobe.icomm.assetplacement.model
com.adobe.livecycle.assetmanager.client
com.adobe.livecycle.assetmanager.client.event
com.adobe.livecycle.assetmanager.client.handler
com.adobe.livecycle.assetmanager.client.managers
com.adobe.livecycle.assetmanager.client.model
com.adobe.livecycle.assetmanager.client.model.cms
com.adobe.livecycle.assetmanager.client.service
com.adobe.livecycle.assetmanager.client.service.search
com.adobe.livecycle.assetmanager.client.service.search.cms
com.adobe.livecycle.assetmanager.client.utils
com.adobe.livecycle.content
com.adobe.livecycle.rca.model
com.adobe.livecycle.rca.model.constant
com.adobe.livecycle.rca.model.document
com.adobe.livecycle.rca.model.participant
com.adobe.livecycle.rca.model.reminder
com.adobe.livecycle.rca.model.stage
com.adobe.livecycle.rca.service
com.adobe.livecycle.rca.service.core
com.adobe.livecycle.rca.service.core.delegate
com.adobe.livecycle.rca.service.process
com.adobe.livecycle.rca.service.process.delegate
com.adobe.livecycle.rca.token
com.adobe.livecycle.ria.security.api
com.adobe.livecycle.ria.security.service
com.adobe.mosaic.layouts
com.adobe.mosaic.layouts.dragAndDrop
com.adobe.mosaic.layouts.interfaces
com.adobe.mosaic.mxml
com.adobe.mosaic.om.constants
com.adobe.mosaic.om.events
com.adobe.mosaic.om.impl
com.adobe.mosaic.om.interfaces
com.adobe.mosaic.skinning
com.adobe.mosaic.sparklib.editors
com.adobe.mosaic.sparklib.optionMenu
com.adobe.mosaic.sparklib.scrollableMenu
com.adobe.mosaic.sparklib.scrollableMenu.skins
com.adobe.mosaic.sparklib.tabLayout
com.adobe.mosaic.sparklib.tabLayout.events
com.adobe.mosaic.sparklib.tabLayout.layouts
com.adobe.mosaic.sparklib.tabLayout.skins
com.adobe.mosaic.sparklib.text
com.adobe.mosaic.sparklib.util
com.adobe.solutions.acm.authoring.presentation
com.adobe.solutions.acm.authoring.presentation.actionbar
com.adobe.solutions.acm.authoring.presentation.common
com.adobe.solutions.acm.authoring.presentation.events
com.adobe.solutions.acm.authoring.presentation.fragment
com.adobe.solutions.acm.authoring.presentation.letter
com.adobe.solutions.acm.authoring.presentation.letter.data
com.adobe.solutions.acm.authoring.presentation.preview
com.adobe.solutions.acm.authoring.presentation.rte
com.adobe.solutions.acm.ccr.presentation
com.adobe.solutions.acm.ccr.presentation.contentcapture
com.adobe.solutions.acm.ccr.presentation.contentcapture.events
com.adobe.solutions.acm.ccr.presentation.contentcapture.preview
com.adobe.solutions.acm.ccr.presentation.datacapture
com.adobe.solutions.acm.ccr.presentation.datacapture.renderers
com.adobe.solutions.acm.ccr.presentation.pdf
com.adobe.solutions.exm
com.adobe.solutions.exm.authoring
com.adobe.solutions.exm.authoring.components.controls
com.adobe.solutions.exm.authoring.components.toolbars
com.adobe.solutions.exm.authoring.domain
com.adobe.solutions.exm.authoring.domain.expression
com.adobe.solutions.exm.authoring.domain.impl
com.adobe.solutions.exm.authoring.domain.method
com.adobe.solutions.exm.authoring.domain.variable
com.adobe.solutions.exm.authoring.enum
com.adobe.solutions.exm.authoring.events
com.adobe.solutions.exm.authoring.model
com.adobe.solutions.exm.authoring.renderer
com.adobe.solutions.exm.authoring.view
com.adobe.solutions.exm.expression
com.adobe.solutions.exm.impl
com.adobe.solutions.exm.impl.method
com.adobe.solutions.exm.method
com.adobe.solutions.exm.mock
com.adobe.solutions.exm.mock.method
com.adobe.solutions.exm.runtime
com.adobe.solutions.exm.runtime.impl
com.adobe.solutions.exm.variable
com.adobe.solutions.prm.constant
com.adobe.solutions.prm.domain
com.adobe.solutions.prm.domain.factory
com.adobe.solutions.prm.domain.impl
com.adobe.solutions.prm.domain.manager
com.adobe.solutions.prm.presentation.asset
com.adobe.solutions.prm.presentation.constant
com.adobe.solutions.prm.presentation.document
com.adobe.solutions.prm.presentation.event
com.adobe.solutions.prm.presentation.file
com.adobe.solutions.prm.presentation.project
com.adobe.solutions.prm.presentation.team
com.adobe.solutions.prm.presentation.util
com.adobe.solutions.prm.service
com.adobe.solutions.prm.services.impl
com.adobe.solutions.prm.vo
com.adobe.solutions.rca.constant
com.adobe.solutions.rca.domain
com.adobe.solutions.rca.domain.common
com.adobe.solutions.rca.domain.factory
com.adobe.solutions.rca.domain.impl
com.adobe.solutions.rca.domain.impl.manager
com.adobe.solutions.rca.domain.manager
com.adobe.solutions.rca.presentation
com.adobe.solutions.rca.presentation.comment
com.adobe.solutions.rca.presentation.constant
com.adobe.solutions.rca.presentation.event
com.adobe.solutions.rca.presentation.gantt
com.adobe.solutions.rca.presentation.gantt.ruler
com.adobe.solutions.rca.presentation.template
com.adobe.solutions.rca.presentation.template.audit
com.adobe.solutions.rca.presentation.template.definition
com.adobe.solutions.rca.presentation.template.documents
com.adobe.solutions.rca.presentation.template.stages
com.adobe.solutions.rca.presentation.util
com.adobe.solutions.rca.service
com.adobe.solutions.rca.services.impl
com.adobe.solutions.rca.vo
com.adobe.solutions.rca.vo.um
com.adobe.viewsource
fl.accessibility
fl.containers
fl.controls
fl.controls.dataGridClasses
fl.controls.listClasses
fl.controls.progressBarClasses
fl.core
fl.data
fl.display
fl.events
fl.ik
fl.lang
fl.livepreview
fl.managers
fl.motion
fl.motion.easing
fl.rsl
fl.text
fl.transitions
fl.transitions.easing
fl.video
flash.accessibility
flash.concurrent
flash.crypto
flash.data
flash.desktop
flash.display
flash.display3D
flash.display3D.textures
flash.errors
flash.events
flash.external
flash.filesystem
flash.filters
flash.geom
flash.globalization
flash.html
flash.media
flash.net
flash.net.dns
flash.net.drm
flash.notifications
flash.permissions
flash.printing
flash.profiler
flash.sampler
flash.security
flash.sensors
flash.system
flash.text
flash.text.engine
flash.text.ime
flash.ui
flash.utils
flash.xml
flashx.textLayout
flashx.textLayout.compose
flashx.textLayout.container
flashx.textLayout.conversion
flashx.textLayout.edit
flashx.textLayout.elements
flashx.textLayout.events
flashx.textLayout.factory
flashx.textLayout.formats
flashx.textLayout.operations
flashx.textLayout.utils
flashx.undo
ga.controls
ga.layouts
ga.model
ga.uiComponents
ga.util
ga.views
ga.wrappers
lc.foundation
lc.foundation.domain
lc.foundation.events
lc.foundation.ui
lc.foundation.util
lc.preloader
lc.procmgmt
lc.procmgmt.commands
lc.procmgmt.domain
lc.procmgmt.events
lc.procmgmt.formbridge
lc.procmgmt.impl
lc.procmgmt.ui.attachments
lc.procmgmt.ui.controls
lc.procmgmt.ui.controls.card
lc.procmgmt.ui.controls.renderer
lc.procmgmt.ui.help
lc.procmgmt.ui.layout
lc.procmgmt.ui.presentationmodel
lc.procmgmt.ui.process
lc.procmgmt.ui.search
lc.procmgmt.ui.startpoint
lc.procmgmt.ui.task
lc.procmgmt.ui.task.form
lc.procmgmt.ui.task.form.commands
lc.procmgmt.ui.tracking
mx.accessibility
mx.automation
mx.automation.air
mx.automation.delegates
mx.automation.delegates.advancedDataGrid
mx.automation.delegates.charts
mx.automation.delegates.containers
mx.automation.delegates.controls
mx.automation.delegates.controls.dataGridClasses
mx.automation.delegates.controls.fileSystemClasses
mx.automation.delegates.core
mx.automation.delegates.flashflexkit
mx.automation.events
mx.binding
mx.binding.utils
mx.charts
mx.charts.chartClasses
mx.charts.effects
mx.charts.effects.effectClasses
mx.charts.events
mx.charts.renderers
mx.charts.series
mx.charts.series.items
mx.charts.series.renderData
mx.charts.styles
mx.collections
mx.collections.errors
mx.containers
mx.containers.accordionClasses
mx.containers.dividedBoxClasses
mx.containers.errors
mx.containers.utilityClasses
mx.controls
mx.controls.advancedDataGridClasses
mx.controls.dataGridClasses
mx.controls.listClasses
mx.controls.menuClasses
mx.controls.olapDataGridClasses
mx.controls.scrollClasses
mx.controls.sliderClasses
mx.controls.textClasses
mx.controls.treeClasses
mx.controls.videoClasses
mx.core
mx.core.windowClasses
mx.data
mx.data.crypto
mx.data.errors
mx.data.events
mx.data.messages
mx.data.mxml
mx.data.offline.errors
mx.data.utils
mx.effects
mx.effects.easing
mx.effects.effectClasses
mx.events
mx.filters
mx.flash
mx.formatters
mx.geom
mx.graphics
mx.graphics.codec
mx.graphics.shaderClasses
mx.logging
mx.logging.errors
mx.logging.targets
mx.managers
mx.messaging
mx.messaging.channels
mx.messaging.config
mx.messaging.errors
mx.messaging.events
mx.messaging.management
mx.messaging.messages
mx.modules
mx.netmon
mx.olap
mx.olap.aggregators
mx.preloaders
mx.printing
mx.resources
mx.rpc
mx.rpc.events
mx.rpc.http
mx.rpc.http.mxml
mx.rpc.livecycle
mx.rpc.mxml
mx.rpc.remoting
mx.rpc.remoting.mxml
mx.rpc.soap
mx.rpc.soap.mxml
mx.rpc.wsdl
mx.rpc.xml
mx.skins
mx.skins.halo
mx.skins.spark
mx.skins.wireframe
mx.skins.wireframe.windowChrome
mx.states
mx.styles
mx.utils
mx.validators
org.osmf.containers
org.osmf.display
org.osmf.elements
org.osmf.events
org.osmf.layout
org.osmf.logging
org.osmf.media
org.osmf.metadata
org.osmf.net
org.osmf.net.dvr
org.osmf.net.httpstreaming
org.osmf.net.metrics
org.osmf.net.qos
org.osmf.net.rtmpstreaming
org.osmf.net.rules
org.osmf.traits
org.osmf.utils
spark.accessibility
spark.automation.delegates
spark.automation.delegates.components
spark.automation.delegates.components.gridClasses
spark.automation.delegates.components.mediaClasses
spark.automation.delegates.components.supportClasses
spark.automation.delegates.skins.spark
spark.automation.events
spark.collections
spark.components
spark.components.calendarClasses
spark.components.gridClasses
spark.components.mediaClasses
spark.components.supportClasses
spark.components.windowClasses
spark.core
spark.effects
spark.effects.animation
spark.effects.easing
spark.effects.interpolation
spark.effects.supportClasses
spark.events
spark.filters
spark.formatters
spark.formatters.supportClasses
spark.globalization
spark.globalization.supportClasses
spark.layouts
spark.layouts.supportClasses
spark.managers
spark.modules
spark.preloaders
spark.primitives
spark.primitives.supportClasses
spark.skins
spark.skins.mobile
spark.skins.mobile.supportClasses
spark.skins.spark
spark.skins.spark.mediaClasses.fullScreen
spark.skins.spark.mediaClasses.normal
spark.skins.spark.windowChrome
spark.skins.wireframe
spark.skins.wireframe.mediaClasses
spark.skins.wireframe.mediaClasses.fullScreen
spark.transitions
spark.utils
spark.validators
spark.validators.supportClasses
xd.core.axm.enterprise.view.components
xd.core.axm.enterprise.view.skins
xd.core.axm.view.components
xd.core.axm.view.components.support

語言元素

全域常數
全域函數
運算子
陳述式、關鍵字和指令
特殊類型

附錄

新增內容
編譯器錯誤
編譯器警告
執行階段錯誤
移轉至 ActionScript 3
支援的字元集
僅限 MXML 標籤
移動 XML 元素
Timed Text 標籤
不建議元素清單
AccessibilityImplementation 常數
如何使用 ActionScript 範例
法律聲明
套件flash.text
類別public class TextField
繼承TextField Inheritance InteractiveObject Inheritance DisplayObject Inheritance EventDispatcher Inheritance Object
子類別 FlexTextField

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

您可以使用 TextField 類別,建立用於顯示和輸入文字的顯示物件。 您可以在「屬性」檢測器中提供實體名稱給文字欄位,並使用 TextField 類別的方法和屬性,以 ActionScript 加以操作。 TextField 實體名稱會顯示在「影片結構檢視器」以及「動作」面板的「插入目標路徑」對話方塊中。

若要以動態的方式建立文字欄位,請使用 TextField() 建構函式。

TextField 類別的方法可讓您設定、選取及操作編寫過程或執行階段中所建立動態或輸入文字欄位的文字。

ActionScript 提供幾種方法,可供您在執行階段格式化文字。 TextFormat 類別可以讓您設定 TextField 物件的字元與段落格式。 您可以使用 TextField.styleSheet 屬性和 StyleSheet 類別,將「階層式樣式表」(CSS) 的樣式套用至文字欄位。 您可以使用 CSS 指定內建 HTML 標籤的樣式、定義新的格式標籤或套用樣式。 您可以將 HTML 格式化文字 (可選擇使用 CSS 樣式) 直接指定給文字欄位。您指定給文字欄位的 HTML 文字可包含內嵌媒體 (影片片段、SWF 檔、GIF 檔、PNG 檔及 JPEG 檔)。 圍繞著內嵌媒體文字的換行的方法,與網頁瀏覽器換行文字圍繞內嵌於 HTML 文件的媒體一樣。

Flash Player 支援可用於格式化文字的 HTML 標籤之子集。 請在 htmlText 屬性的描述中,參閱支援之 HTML 標籤的清單。

檢視範例

相關 API 元素



公用屬性
 屬性定義自
 InheritedaccessibilityImplementation : AccessibilityImplementation
對此 InteractiveObject 實體目前的輔助功能實作 (AccessibilityImplementation)。
InteractiveObject
 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
 InheritedblendShader : Shader
[唯寫] 設定用來混合前景和背景的著色器。
DisplayObject
  border : Boolean
會指定文字欄位是否具有邊框。
TextField
  borderColor : uint
文字欄位邊框的顏色。
TextField
  bottomScrollV : int
[唯讀] 整數 (從 1 開始的索引),指出目前在指定之文字欄位中,可以看見的最底端字行。
TextField
 InheritedcacheAsBitmap : Boolean
如果設定為 true,Flash 執行階段會快取顯示物件的內部點陣圖表示法。
DisplayObject
 Inherited    cacheAsBitmapMatrix : Matrix
如果為非 null,當 cacheAsBitmap 設定為 true 時,這個 Matrix 物件會定義顯示物件的顯示方法。
DisplayObject
  caretIndex : int
[唯讀] 插入點 (跳脫字元) 位置的索引。
TextField
  condenseWhite : Boolean
Boolean 值,指定在具有 HTML 文字的文字欄位中,是否移除額外的空白字元 (空格、斷行符號等等)。
TextField
 Inheritedconstructor : Object
類別物件的參照或是特定物件實體的建構函數。
Object
 InheritedcontextMenu : NativeMenu
指定與此物件有關聯的快顯選單。
InteractiveObject
  defaultTextFormat : flash.text: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
[唯讀] 文字欄位中的字元數。
TextField
 InheritedloaderInfo : LoaderInfo
[唯讀] 會傳回 LoaderInfo 物件,其中包含關於載入此顯示物件所屬之檔案的資訊。
DisplayObject
 Inheritedmask : DisplayObject
呼叫之顯示物件會以指定的 mask 物件遮蓋。
DisplayObject
  maxChars : int
文字欄位可以包含的最大字元數,也就是使用者可輸入的字元數。
TextField
  maxScrollH : int
[唯讀] scrollH 的最大值。
TextField
  maxScrollV : int
[唯讀] scrollV 的最大值。
TextField
 InheritedmetaData : Object
如果中繼資料是透過 PlaceObject4 標籤與 SWF 檔案中的這個 DisplayObject 實體一同儲存,則會取得 DisplayObject 實體的中繼資料物件。
DisplayObject
 InheritedmouseEnabled : Boolean
指定此物件是否接收滑鼠或其他使用者輸入及訊息。
InteractiveObject
  mouseWheelEnabled : Boolean
Boolean 值,指出當使用者按一下文字欄位並滾動滑鼠滾輪時,Flash Player 是否會自動捲動多行文字欄位。
TextField
 InheritedmouseX : Number
[唯讀] 指出滑鼠或使用者輸入裝置位置的 x 座標,以像素為單位。
DisplayObject
 InheritedmouseY : Number
[唯讀] 指出滑鼠或使用者輸入裝置位置的 y 座標,以像素為單位。
DisplayObject
  multiline : Boolean
指出欄位是否為多行文字欄位。
TextField
 Inheritedname : String
指出 DisplayObject 的實體名稱。
DisplayObject
 InheritedneedsSoftKeyboard : Boolean
指定虛擬鍵盤 (螢幕上的軟體鍵盤) 是否應在此 InteractiveObject 實體接收到焦點時顯示。
InteractiveObject
  numLines : int
[唯讀] 會定義多行文字欄位中的文字行數。
TextField
 InheritedopaqueBackground : Object
會指定顯示物件是否不透明,並具有特定背景顏色。
DisplayObject
 Inheritedparent : DisplayObjectContainer
[唯讀] 指出包含此顯示物件的 DisplayObjectContainer 物件。
DisplayObject
  restrict : String
指出使用者能夠輸入文字欄位中的字元組。
TextField
 Inheritedroot : DisplayObject
[唯讀] 對載入之 SWF 檔案的顯示物件而言,root 屬性就是該 SWF 檔案所呈現之顯示清單樹狀結構部分的最上層顯示物件。
DisplayObject
 Inheritedrotation : Number
指出 DisplayObject 實體的旋轉度數 (從該物件原本方向算起)。
DisplayObject
 InheritedrotationX : Number
表示 DisplayObject 實體相對於 3D 父輩容器從原始方向旋轉的 x 軸旋轉 (以度數為單位)。
DisplayObject
 InheritedrotationY : Number
表示 DisplayObject 實體相對於 3D 父輩容器從原始方向旋轉的 y 軸旋轉 (以度數為單位)。
DisplayObject
 InheritedrotationZ : Number
表示 DisplayObject 實體相對於 3D 父輩容器從原始方向旋轉的 z 軸旋轉 (以度數為單位)。
DisplayObject
 Inheritedscale9Grid : Rectangle
目前產生效用的縮放格線。
DisplayObject
 InheritedscaleX : Number
指出從註冊點套用的物件水平縮放 (百分比)。
DisplayObject
 InheritedscaleY : Number
指出從物件註冊點套用的物件垂直縮放 (百分比)。
DisplayObject
 InheritedscaleZ : Number
指出從物件註冊點套用的物件深度縮放 (百分比)。
DisplayObject
  scrollH : int
目前的水平捲動位置。
TextField
 InheritedscrollRect : Rectangle
顯示物件的捲動矩形範圍。
DisplayObject
  scrollV : int
文字欄位中文字的垂直位置。
TextField
  selectable : Boolean
指出文字欄位是否可選取的 Boolean 值。
TextField
  selectionBeginIndex : int
[唯讀] 目前選取範圍中,第一個字元的字元索引值 (從零開始)。
TextField
  selectionEndIndex : int
[唯讀] 目前選取範圍中,最後一個字元的字元索引值 (從零開始)。
TextField
  sharpness : Number
在這個文字欄位中,文字邊緣的清晰度。
TextField
 Inherited    softKeyboard : String
控制軟體鍵盤的外觀。
InteractiveObject
 InheritedsoftKeyboardInputAreaOfInterest : Rectangle
定義顯示軟體鍵盤時,應保留於螢幕上的區域 (iOS 未提供)。
InteractiveObject
 Inheritedstage : Stage
[唯讀] 顯示物件的「舞台」。
DisplayObject
  styleSheet : StyleSheet
將樣式表附加至文字欄位。
TextField
 InheritedtabEnabled : Boolean
會指定這個物件是否在停駐點順序中。
InteractiveObject
 InheritedtabIndex : int
會指定 SWF 檔中的物件停駐點順序。
InteractiveObject
  text : String
做為文字欄位中目前文字的字串。
TextField
  textColor : uint
文字欄位中文字的顏色,以十六進位格式表示。
TextField
  textHeight : Number
[唯讀] 文字的高度,以像素為單位。
TextField
  textInteractionMode : String
[唯讀] 互動模式屬性,預設值為 TextInteractionMode.NORMAL。
TextField
  textWidth : Number
[唯讀] 文字的寬度,以像素為單位。
TextField
  thickness : Number
在這個文字欄位中,字符邊緣的粗細。
TextField
 Inheritedtransform : flash.geom:Transform
這是一個物件,具有和顯示物件的矩陣、顏色轉換和像素邊界有關的屬性。
DisplayObject
  type : String
文字欄位的類型。
TextField
  useRichTextClipboard : Boolean
會指定文字格式是否隨著文字一起複製和貼上。
TextField
 Inheritedvisible : Boolean
不管是否看得見顯示物件。
DisplayObject
 Inheritedwidth : Number
會指出顯示物件的寬度,以像素為單位。
DisplayObject
  wordWrap : Boolean
指出文字欄位是否具有文字換行功能的 Boolean 值。
TextField
 Inheritedx : Number
指出 DisplayObject 實體相對於父輩 DisplayObjectContainer 之區域座標的 x 座標。
DisplayObject
 Inheritedy : Number
指出 DisplayObject 實體相對於父輩 DisplayObjectContainer 之區域座標的 y 座標。
DisplayObject
 Inheritedz : Number
表示 DisplayObject 實體相對於 3D 父輩容器的 z 座標位置 (沿著 z 軸)。
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
  
對於使用 <img> 標籤新增至 HTML 格式之文字欄位的影像或 SWF 檔,傳回指定之 id 的 DisplayObject 參考。
TextField
  
會在 x 和 y 參數所指定的點,傳回字行的索引值 (從零開始)。
TextField
  
會傳回字行的索引值 (從零開始),該字行包含 charIndex 參數所指定的字元。
TextField
  
getLineLength(lineIndex:int):int
會傳回特定文字行中的字元數。
TextField
  
會傳回關於指定之文字行的公制字資訊。
TextField
  
getLineOffset(lineIndex:int):int
會傳回 lineIndex 參數所指定之字行中,第一個字元的字元索引。
TextField
  
會傳回 lineIndex 參數所指定之字行的文字。
TextField
  
指定字元索引,會傳回包含指定之字元的段落長度。
TextField
 Inherited
getRect(targetCoordinateSpace:DisplayObject):Rectangle
根據 targetCoordinateSpace 參數所定義的座標系統,並排除形狀上的任何筆畫,傳回可定義顯示物件邊界的矩形。
DisplayObject
  
getTextFormat(beginIndex:int = -1, endIndex:int = -1):flash.text:TextFormat
會傳回 TextFormat 物件,包含 beginIndex 和 endIndex 參數所指定之文字範圍的格式資訊。
TextField
 Inherited
將 point 物件從「舞台」(全域) 座標轉換成顯示物件的 (區域) 座標。
DisplayObject
 Inherited
將二維點從「舞台」(全域) 座標轉換為三維顯示物件的 (區域) 座標。
DisplayObject
 Inherited
會檢查 EventDispatcher 物件是否有對特定的事件類型註冊偵聽程式。
EventDispatcher
 Inherited
指出物件是否有已定義的指定屬性。
Object
 Inherited
評估顯示物件的範圍框,看它是否與 obj 顯示物件的範圍框重疊或相交。
DisplayObject
 Inherited
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
評估顯示物件,看它是否與 x 和 y 參數所指定的點重疊或相交。
DisplayObject
  
isFontCompatible(fontName:String, fontStyle:String):Boolean
[靜態] 如果指定的 fontName 和 fontStyle 提供內嵌字體,而 Font.fontType 為 flash.text.FontType.EMBEDDED 時,則傳回 true。
TextField
 Inherited
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。
Object
 Inherited
將三維顯示物件的 (區域) 座標的三維點轉換為「舞台」(全域) 座標中的二維點。
DisplayObject
 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
升起顯示虛擬鍵盤。
InteractiveObject
 Inherited
為迴圈作業設定動態屬性的可用性。
Object
  
setSelection(beginIndex:int, endIndex:int):void
根據第一個和最後一個字元指定的索引值 (以 beginIndex 和 endIndex 參數指定),設定選取文字。
TextField
  
setTextFormat(format:flash.text:TextFormat, beginIndex:int = -1, endIndex:int = -1):void
會將 format 參數所指定的文字格式,套用至文字欄位中的指定文字。
TextField
 Inherited
傳回代表此物件的字串,根據地區特定慣例進行格式化。
Object
 Inherited
會傳回指定之物件的字串形式。
Object
 Inherited
會傳回指定之物件的基本值。
Object
 Inherited
檢查此 EventDispatcher 物件是否已註冊事件偵聽程式,或者此物件的任何祖系已為特定事件類型註冊事件偵聽程式。
EventDispatcher
事件
 事件 摘要 定義自
 Inherited[廣播事件] 當 Flash Player 或 AIR 應用程式取得作業系統焦點並成為作用中時傳送。EventDispatcher
 Inherited當顯示物件加入顯示清單中時傳送。DisplayObject
 Inherited會在顯示物件加入舞台上的顯示清單時,以直接或是透過加入包含該顯示物件之子樹狀結構的方式傳送。DisplayObject
  在修改控制項值之後傳送,不同於在修改值之前傳送的 textInput 事件。TextField
 Inherited當使用者從文字快顯選單中選取「清除」(或「刪除」) 時傳送。InteractiveObject
 Inherited會當使用者在相同的 InteractiveObject 上方按下並放開使用者的指向裝置主按鈕時傳送。InteractiveObject
 Inherited
    contextMenu
當使用者手勢在 AIR 應用程式中觸發與此互動式物件相關聯的快顯選單時傳送。InteractiveObject
 Inherited當使用者針對複製作業啟動平台特有的快速鍵組合或從文字快顯選單中選取「複製」時傳送。InteractiveObject
 Inherited當使用者針對剪下作業啟動平台特有的快速鍵組合或從文字快顯選單中選取「剪下」時傳送。InteractiveObject
 Inherited[廣播事件] 當 Flash Player 或 AIR 應用程式失去作業系統焦點並成為非作用中時傳送。EventDispatcher
 Inherited在 InteractiveObject 物件的 doubleClickEnabled 旗標設為 true 的情況下,當使用者在相同的物件上方連續兩次快速按下並放開指標裝置主要按鈕時傳送。InteractiveObject
 Inherited[廣播事件] 當播放磁頭進入新影格時傳送。DisplayObject
 Inherited[廣播事件] 當播放磁頭結束目前影格時傳送。DisplayObject
 Inherited當顯示物件取得焦點之後傳送。InteractiveObject
 Inherited當顯示物件失去焦點時傳送。InteractiveObject
 Inherited[廣播事件] 在影格顯示物件的建構函式執行之後,且影格指令碼執行之前傳送。DisplayObject
 Inherited當使用者沿著觸控面與 InteractiveObject 實體建立接觸點 (例如沿著 Apple TV 的 Siri Remote 觸控面點選),某些裝置可能也會將此接觸解譯為數個觸控事件的組合。InteractiveObject
 Inherited當使用在觸控裝置上的同一個 InteractiveObject 實體上按下兩個接觸點後送出 (例如在行動電話或平板電腦觸控螢幕的顯示物件上方,以兩支手指按下後鬆開)。InteractiveObject
 Inherited當使用者在觸控裝置上,將接觸點移動到 InteractiveObject 實體上方後傳送 (例如,在行動電話或平板電腦觸控螢幕的顯示物件上,由左向右移動手指)。InteractiveObject
 Inherited當使用者在 InteractiveObject 實體的接觸點上做出旋轉手勢後傳送 (例如兩指觸摸行動電話或平板電腦的觸控螢幕,然後手指在顯示物件上旋轉)。InteractiveObject
 Inherited當使用者在與 InteractiveObject 實體的某個接觸點上做出揮動手勢後傳送 (例如,三指併在一起觸碰行動電話或平板電腦的觸控螢幕,然後在顯示物件上快速平行移動手指)。InteractiveObject
 Inherited當使用者與 InteractiveObject 實體建立接觸點,然後在觸控裝置上點一下後送出 (例如,將多根手指放到行動電話或平板電腦觸控螢幕的顯示物件上以開啟選單,然後其中一根手點一下,選取選單項目)。InteractiveObject
 Inherited當使用者在 InteractiveObject 實體的某個接觸點上做出放大縮小手勢後傳送 (例如兩指併在一起觸摸行動電話或平板電腦的觸控螢幕,然後手指在顯示物件上快速張開)。InteractiveObject
 Inherited這個事件會送出至任何支援 IME 內嵌輸入的用戶端應用程式。InteractiveObject
 Inherited會當使用者按下按鍵時傳送。InteractiveObject
 Inherited當使用者嘗試使用鍵盤瀏覽變更焦點時傳送。InteractiveObject
 Inherited會當使用者放開按鍵時傳送。InteractiveObject
  當使用者按一下已啟用 HTML 功能之文字欄位中的超連結,並且其中的 URL 是以 "event:" 開始時,便會傳送。TextField
 Inherited當使用者在相同的 InteractiveObject 上方按下並放開使用者的指向裝置中間按鈕時傳送。InteractiveObject
 Inherited當使用者將指向裝置的中間按鈕移至 InteractiveObject 實體上方按下時傳送。InteractiveObject
 Inherited當使用者將指向裝置按鈕移至 InteractiveObject 實體上方放開時傳送。InteractiveObject
 Inherited當使用者將指向裝置按鈕移至 InteractiveObject 實體上方按下時傳送。InteractiveObject
 Inherited會當使用者嘗試使用指向裝置變更焦點時傳送。InteractiveObject
 Inherited會當指向裝置停在 InteractiveObject 上方的情況下使用者將其移動時傳送。InteractiveObject
 Inherited會當使用者將指向裝置移開 InteractiveObject 實體時傳送。InteractiveObject
 Inherited會當使用者將指向裝置移至 InteractiveObject 實體上方時傳送。InteractiveObject
 Inherited當使用者將指向裝置按鈕移至 InteractiveObject 實體上方放開時傳送。InteractiveObject
 Inherited當滑鼠滾輪在 InteractiveObject 實體上方轉動時傳送。InteractiveObject
 Inherited當使用者釋放手勢時,由拖曳初始程式 InteractiveObject 傳送。InteractiveObject
 Inherited已在目標 InteractiveObject 上放下拖曳的物件,而且已呼叫 DragManager.acceptDragDrop() 接受該放開的資料時,由此目標 InteractiveObject 傳送。InteractiveObject
 Inherited當手勢進入 InteractiveObject 的邊界時,由此 InteractiveObject 傳送。InteractiveObject
 Inherited當手勢離開 InteractiveObject 的邊界時,由此 InteractiveObject 傳送。InteractiveObject
 Inherited當拖曳手勢還留在 InteractiveObject 的邊界內,由此 InteractiveObject 持續傳送。InteractiveObject
 Inherited在呼叫 DragManager.doDrag() 進行拖曳作業初期,由指定做為拖曳初始程式的 InteractiveObject 傳送。InteractiveObject
 Inherited在呼叫 DragManager.doDrag() 進行拖曳作業期間,由指定做為拖曳初始程式的 InteractiveObject 傳送。InteractiveObject
 Inherited當使用者針對貼上作業啟動平台特有的快速鍵組合或從文字快顯選單中選取「貼上」時傳送。InteractiveObject
 Inherited在使用者將作用中觸控筆往下移至超過螢幕鄰近偵測邊框時傳送。InteractiveObject
 Inherited
    proximityEnd
在使用者將作用中觸控筆提到螢幕鄰近偵測邊框時傳送。InteractiveObject
 Inherited在使用者將作用中觸控筆移到螢幕上方,而其餘仍在鄰近偵測邊框內時傳送。InteractiveObject
 Inherited
    proximityOut
在使用者將作用中觸控筆移出這個 InteractiveObject 之外,而其餘仍在螢幕的鄰近偵測邊框內時傳送。InteractiveObject
 Inherited在使用者直接將作用中觸控筆移到這個 InteractiveObject 上方,而其餘仍在螢幕的鄰近偵測邊框內時傳送。InteractiveObject
 Inherited在使用者將作用中觸控筆移出這個 InteractiveObject 及其任一子系之外,而其餘仍在螢幕的鄰近偵測邊框內時傳送。InteractiveObject
 Inherited在使用者透過這個 InteractiveObject,從顯示清單中後代的物件樹狀結構之外移動作用中觸控筆時傳送 (而其餘仍在螢幕的鄰近偵測邊框內)。InteractiveObject
 Inherited當使用者第一次按下 InteractiveObject 實體上方的按鈕,然後將指向裝置滑出 InteractiveObject 實體之後即放開指向裝置上的按鈕時傳送。InteractiveObject
 Inherited會當顯示物件將要從顯示清單移除時傳送。DisplayObject
 Inherited會在顯示物件即將從顯示清單移除時,以直接或是透過移除包含該顯示物件之子樹狀結構的方式傳送。DisplayObject
 Inherited[廣播事件] 當顯示清單將要更新和顯示時傳送。DisplayObject
 Inherited當使用者在相同的 InteractiveObject 上方按下並放開使用者的指向裝置右邊按鈕時傳送。InteractiveObject
 Inherited當使用者將指向裝置按鈕移至 InteractiveObject 實體上方按下時傳送。InteractiveObject
 Inherited當使用者將指向裝置按鈕移至 InteractiveObject 實體上方放開時傳送。InteractiveObject
 Inherited會當使用者將指向裝置移開 InteractiveObject 實體時傳送。InteractiveObject
 Inherited會當使用者將指向裝置移至 InteractiveObject 實體上方時傳送。InteractiveObject
  在使用者捲動之後,由 TextField 物件傳送。TextField
 Inherited當使用者針對全選作業啟動平台特有的快速鍵組合或從文字快顯選單中選取「全選」時傳送。InteractiveObject
 Inherited升起顯示軟體鍵盤之後立即傳送。InteractiveObject
 Inherited升起顯示軟體鍵盤前立即傳送。InteractiveObject
 Inherited降下隱藏軟體鍵盤之後立即傳送。InteractiveObject
 Inherited在物件的 tabChildren 旗標值變更時傳送。InteractiveObject
 Inherited在物件的 tabEnabled 旗標變更時傳送。InteractiveObject
 Inherited在物件的 tabIndex 屬性值變更時傳送。InteractiveObject
  當使用者輸入一個或多個文字字元時,Flash Player 便會傳送 textInput 事件。TextField
  當使用者變更文字欄位的互動模式時,Flash Player 會傳送 textInteractionModeChange 事件。TextField
 Inherited當使用者在第一次接觸觸控裝置後傳送 (例如手指觸摸行動電話或平板電腦的觸控螢幕)。InteractiveObject
 Inherited當使用者在觸控裝置上移除接觸點後傳送 (例如在行動電話或平板電腦觸控螢幕上移開手指)。InteractiveObject
 Inherited當使用者觸控裝置時傳送,並且連續不斷地傳送,直到接觸點移除為止。InteractiveObject
 Inherited當使用者在觸控裝置中,將接觸點移出 InteractiveObject 實體後送出 (例如在行動電話或平板電腦的觸控螢幕上,將手指從顯示物件移至另一個顯示物件)。InteractiveObject
 Inherited當使用者在觸控裝置中將接觸點移至 InteractiveObject 實體上方後送出 (例如在行動電話或平板電腦的觸控螢幕上,將手指從顯示物件外面的某一點,往顯示物件上方拖曳)。InteractiveObject
 Inherited當使用者在觸控裝置上,將接觸點從 InteractiveObject 實體移出後送出 (例如,在行動電話或平板電腦的觸控螢幕上,將手指從顯示物件上方拖曳到顯示物件以外)。InteractiveObject
 Inherited當使用者在觸控裝置中將接觸點移至 InteractiveObject 實體上方後送出 (例如在行動電話或平板電腦的觸控螢幕上,將手指從顯示物件外面的某一點,往顯示物件上方拖曳)。InteractiveObject
 Inherited當使用者在觸控裝置的同一個 InteractiveObject 實體上,在原先開始接觸點放開後送出 (例如在行動電話或平板電腦觸控螢幕上的顯示物件上方,以手指按下某個點後又鬆開)。InteractiveObject
屬性詳細資訊

alwaysShowSelection

屬性
alwaysShowSelection:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

當設定為 true 而且文字欄位不在焦點中時,Flash Player 便會將文字欄位中的選取範圍反白標示為灰色。 當設定為 false 而且文字欄位不在焦點中時,Flash Player 便不會反白標示文字欄位中的選取範圍。

預設值為 false。



實作
    public function get alwaysShowSelection():Boolean
    public function set alwaysShowSelection(value:Boolean):void

相關 API 元素


範例  ( 如何使用本範例 )
編譯並執行下列檔案。 當您執行檔案時,請在兩個文字欄位中個別拖曳選取文字,並且要針對您在兩個文字欄位中選取文字 (變更焦點) 時所反白標示的選取範圍,注意其中的差異:
    package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class TextField_alwaysShowSelection extends Sprite {
        public function TextField_alwaysShowSelection() {
            var label1:TextField = createCustomTextField(0, 20, 200, 20);
            label1.text = "This text is selected.";
            label1.setSelection(0, 9);
            label1.alwaysShowSelection = true;

            var label2:TextField = createCustomTextField(0, 50, 200, 20);
            label2.text = "Drag to select some of this text.";
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x; result.y = y;
            result.width = width; result.height = height;
            addChild(result);
            return result;
        }
    }
}

antiAliasType

屬性 
antiAliasType:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9

對此文字欄位使用的消除鋸齒類型。 請針對此屬性使用 flash.text.AntiAliasType 常數。 只有在字體是嵌入時 (embedFonts 屬性設定為 true) 才能控制這個設定。 預設值是 flash.text.AntiAliasType.NORMAL

若要設定此屬性,請使用下列字串值:

字串值說明
flash.text.AntiAliasType.NORMAL套用一般文字消除鋸齒。 此值符合 Flash Player 7 和舊版所使用的消除鋸齒類型。
flash.text.AntiAliasType.ADVANCED套用進階消除鋸齒,讓文字更易於辨識。(這項功能從 Flash Player 8 開始提供)。 進階消除鋸齒可呈現超高品質的小字體外觀。 特別適合用於含有大量小型文字的應用程式。大於 48 點的字體則不建議使用進階消除鋸齒。



實作
    public function get antiAliasType():String
    public function set antiAliasType(value:String):void

相關 API 元素

autoSize

屬性 
autoSize:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

控制文字欄位的自動調整大小和對齊方式。 TextFieldAutoSize 常數的可接受值:TextFieldAutoSize.NONE (預設值),TextFieldAutoSize.LEFTTextFieldAutoSize.RIGHTTextFieldAutoSize.CENTER

如果 autoSize 設定為 TextFieldAutoSize.NONE (預設值),就不會調整大小。

如果 autoSize 設定為 TextFieldAutoSize.LEFT,就會將文字視為靠左對齊的文字,這表示文字欄位的左方邊界會維持固定,而且文字欄位的單一字行若有任何調整大小的行為,都會發生在右方邊界。 如果文字包含斷行符號 (例如,"\n""\r"),也會調整底部的大小,以配合下一行文字。 如果 wordWrap 也設定為 true,則只有文字欄位底部才會調整大小,右方邊界則維持不變。

如果 autoSize 設定為 TextFieldAutoSize.RIGHT,就會將文字視為靠右對齊的文字,這表示文字欄位的右方邊界會維持固定,而且文字欄位的單一字行若有任何調整大小的行為,都會發生在左方邊界。 如果文字包含斷行符號 (例如,"\n" 或 "\r"),也會調整底部的大小,以配合下一行文字。 如果 wordWrap 也設定為 true,則只有文字欄位底部才會調整大小,左方邊界則維持不變。

如果 autoSize 設定為 TextFieldAutoSize.CENTER,則文字會被視為置中對齊的文字,表示文字欄位的單一字行若有任何調整大小的行為,都會平均分配到左右方的邊界。 如果文字包含斷行符號 (例如,"\n""\r"),也會調整底部的大小,以配合下一行文字。 如果 wordWrap 也設定為 true,則只有文字欄位底部才會調整大小,左右方邊界則維持不變。



實作
    public function get autoSize():String
    public function set autoSize(value:String):void

擲回值
ArgumentError — 指定的 autoSize 不是 flash.text.TextFieldAutoSize 的成員。

相關 API 元素

background

屬性 
background:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會指定文字欄位是否具有背景填色。 如果為 true,文字欄位就會有背景填色; 如果 false,則文字欄位不會有背景填色。 請使用 backgroundColor 屬性設定文字欄位的背景顏色。

預設值為 false。



實作
    public function get background():Boolean
    public function set background(value:Boolean):void

相關 API 元素

backgroundColor

屬性 
backgroundColor:uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字欄位背景的顏色。 預設值為 0xFFFFFF (白色)。 即使目前沒有背景,您依然可以擷取或設定這個屬性,不過只有在文字欄位的 background 屬性設定為 true 時,才能看見這個顏色。



實作
    public function get backgroundColor():uint
    public function set backgroundColor(value:uint):void

相關 API 元素

border

屬性 
border:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會指定文字欄位是否具有邊框。 如果是 true,文字欄位便具有邊框; 如果是 false,文字欄位則沒有邊框。 請使用 borderColor 屬性設定邊框顏色。

預設值為 false。



實作
    public function get border():Boolean
    public function set border(value:Boolean):void

相關 API 元素

borderColor

屬性 
borderColor:uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字欄位邊框的顏色。 預設值為 0x000000 (黑色)。 即使目前沒有邊框,您依然可以擷取或設定這個屬性,不過只有在文字欄位的 border 屬性設定為 true 時,才能看見這個顏色。



實作
    public function get borderColor():uint
    public function set borderColor(value:uint):void

相關 API 元素

bottomScrollV

屬性 
bottomScrollV:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

整數 (從 1 開始的索引),指出目前在指定之文字欄位中,可以看見的最底端字行。 將文字欄位視為文字區塊上的視窗。 scrollV 屬性是視窗中,最頂端之可見字行的索引 (從 1 開始)。

在文字欄位中,scrollVbottomScrollV 字行間的所有文字目前都是可見的。



實作
    public function get bottomScrollV():int

相關 API 元素

caretIndex

屬性 
caretIndex:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

插入點 (跳脫字元) 位置的索引。 如果沒有顯示插入點,其值就是您將焦點還原至欄位時的插入點位置 (通常會是插入點的最後位置,不曾有過焦點時則會是 0)。

合併選取範圍索引從零開始記算 (例如,第一個位置是 0,第二個位置是 1,依此類推)。



實作
    public function get caretIndex():int

相關 API 元素


範例  ( 如何使用本範例 )
此範例會建立 TextField 實體並填入文字。 然後指派事件偵聽程式,如此當使用者按一下此 TextField 時,就會呼叫 printCursorPosition 方法。 之後就會輸出 caretIndexselectionBeginIndexselectionEndIndex 屬性的值。

請執行此範例,並嘗試在 TextField 中按一下以選取文字。 然後,在欄位中按一下而不選取文字。 當您按一下文字但不做選取動作時,caretIndex 屬性表示要放入插入點的位置,而 selectionBeginIndexselectionEndIndex 屬性則等於 caretIndex 屬性值。

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class TextField_caretIndex extends Sprite {
        public function TextField_caretIndex() {
            var tf:TextField = createCustomTextField(10, 10, 100, 100);
            tf.wordWrap = true;
            tf.type = TextFieldType.INPUT;
            tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
            tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
        }

        private function printCursorPosition(event:MouseEvent):void {
            var tf:TextField = TextField(event.target);
            trace("caretIndex:", tf.caretIndex);
            trace("selectionBeginIndex:", tf.selectionBeginIndex);
            trace("selectionEndIndex:", tf.selectionEndIndex);
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            addChild(result);
            return result;
        }
    }
}

condenseWhite

屬性 
condenseWhite:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

Boolean 值,指定在具有 HTML 文字的文字欄位中,是否移除額外的空白字元 (空格、斷行符號等等)。預設值為 falsecondenseWhite 屬性只會影響以 htmlText 屬性 (而非 text 屬性) 設定的文字。 如果您以 text 屬性設定文字,便會忽略 condenseWhite

如果 condenseWhite 是設定為 true,請使用標準 HTML 命令 (如 <BR><P>),將斷行符號放置在文字欄位中。

設定 htmlText 屬性之前,請先設定 condenseWhite 屬性。



實作
    public function get condenseWhite():Boolean
    public function set condenseWhite(value:Boolean):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會說明將 condenseWhite 設定為 false 以及將它設定為 true 兩者之間的差異:
package {
    import flash.display.Sprite;
    import flash.text.TextField;

    public class TextField_condenseWhite extends Sprite {
        public function TextField_condenseWhite() {
            var tf1:TextField = createCustomTextField(0, 0, 200, 50);
            tf1.condenseWhite = false;
            tf1.htmlText = "keep    on\n\ttruckin'";
            
            var tf2:TextField = createCustomTextField(0, 120, 200, 50);
            tf2.condenseWhite = true;
            tf2.htmlText = "keep    on\n\ttruckin'";
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            result.border = true;
            addChild(result);
            return result;
        }
    }
}

defaultTextFormat

屬性 
defaultTextFormat:flash.text:TextFormat

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指定套用至新插入之文字 (例如,使用者所輸入的文字,或是以 replaceSelectedText() 方法插入的文字) 的格式。

注意:選取要用 setSelection()replaceSelectedText() 取代的字元時,唯有已達到且包含所選取的文字最後的字元時,才會套用 defaultTextFormat。底下是一個範例:

     var my_txt:TextField new TextField();
     my_txt.text = "Flash Macintosh version";
     var my_fmt:TextFormat = new TextFormat();
     my_fmt.color = 0xFF0000;
     my_txt.defaultTextFormat = my_fmt;
     my_txt.setSelection(6,15); // partial text selected - defaultTextFormat not applied
     my_txt.setSelection(6,23); // text selected to end - defaultTextFormat applied
     my_txt.replaceSelectedText("Windows version");
     

當您存取 defaultTextFormat 屬性時,傳回的 TextFormat 物件會定義所有屬性。 沒有屬性是 null

注意: 如果已經將樣式表套用至文字欄位,就不能設定這個屬性。



實作
    public function get defaultTextFormat():flash.text:TextFormat
    public function set defaultTextFormat(value:flash.text:TextFormat):void

擲回值
Error — 此方法不可用在具有樣式表的文字欄位。

相關 API 元素

displayAsPassword

屬性 
displayAsPassword:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指定文字欄位是否為密碼文字欄位。 如果此屬性的值是 true,就會將文字欄位視為密碼文字欄位,並會使用星號隱藏輸入字元,而不會顯示實際字元。 如果是 false,就不會將文字欄位視為密碼文字欄位。 啟用密碼模式時,「剪下」與「複製」命令及其對應的鍵盤快速鍵都不會具有作用。 這個安全性機制可預防惡意使用者利用捷徑來找出無人看管的電腦上之密碼。

預設值為 false。



實作
    public function get displayAsPassword():Boolean
    public function set displayAsPassword(value:Boolean):void

embedFonts

屬性 
embedFonts:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會指定是否要使用內嵌的字體外框顯示。 如果為 false,Flash Player 會使用裝置字體顯示文字欄位。

如果您將文字欄位的 embedFonts 屬性設定為 true,就必須使用套用至文字欄位的 TextFormat 物件之 font 屬性,指定該文字的字體。 如果指定的字體沒有嵌入 SWF 檔,文字就不會顯示。

預設值為 false。



實作
    public function get embedFonts():Boolean
    public function set embedFonts(value:Boolean):void

相關 API 元素

gridFitType

屬性 
gridFitType:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9

對此文字欄位使用的格線符合類型。 只有在文字欄位的 flash.text.AntiAliasType 屬性設定為 flash.text.AntiAliasType.ADVANCED 時,才會套用這個屬性。

格線符合的類型,用於決定 Flash Player 是否會強制強的水平和垂直線,以符合像素或子像素格線,或是不符合任何格線。

針對 flash.text.GridFitType 屬性,您可以使用下列字串值:

字串值說明
flash.text.GridFitType.NONE指定不使用格線符合。 不強制文字內的水平和垂直線與像素格線符合。 建議針對動畫或大型字體使用這個設定。
flash.text.GridFitType.PIXEL指定強的水平和垂直線都會與像素格線符合。 此設定只能用在靠左對齊的文字欄位。 若要使用這個設定,文字欄位的 flash.dispaly.AntiAliasType 屬性必須設定為 flash.text.AntiAliasType.ADVANCED。 一般而言,此設定能為靠左對齊的文字提供最佳易讀性。
flash.text.GridFitType.SUBPIXEL指定強的水平和垂直線與 LCD 顯示器上的子像素格線符合 若要使用這個設定,文字欄位的 flash.text.AntiAliasType 屬性必須設定為 flash.text.AntiAliasType.ADVANCEDflash.text.GridFitType.SUBPIXEL 設定通常適用於靠右對齊或置中的動態文字,有時也是用來平衡動畫和文字品質的有用設定。

預設值為 pixel。



實作
    public function get gridFitType():String
    public function set gridFitType(value:String):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例顯示具有不同 gridFitType 屬性設定的三個文字欄位。當您使用這個範例時,請注意頭兩行之易讀性的差異。也請注意靠左對齊文字的最佳 GridFitType.PIXEL 使用及靠右對齊文字的最佳 GridFitType.SUBPIXEL 使用。
package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.text.TextFieldAutoSize;
    import flash.text.AntiAliasType;
    import flash.text.GridFitType;

    public class gridFitTypeExample extends Sprite
    {
        public function gridFitTypeExample()
        {
    var format1:TextFormat = new TextFormat();
    format1.font="Arial";
    format1.size=12;

    var tf1:TextField = createCustomTextField(0,0,format1,"NONE",TextFieldAutoSize.LEFT,GridFitType.NONE);
    
    var tf2:TextField = createCustomTextField(0,30,format1,"PIXEL",TextFieldAutoSize.LEFT,GridFitType.PIXEL);

    var tf3:TextField = createCustomTextField(300,60,format1,"SUBPIXEL",TextFieldAutoSize.RIGHT,GridFitType.SUBPIXEL);

        }
        private function createCustomTextField(x:Number,y:Number,fm:TextFormat,tl:String,tfs:String,gft:String):TextField 
        {
            var result:TextField = new TextField();
            result.x=x;
            result.y=y;
            result.embedFonts=true;
            result.antiAliasType=AntiAliasType.ADVANCED;
            result.text="This text uses a gridFitType of " + tl;
            result.autoSize=tfs;
        result.gridFitType=gft;
            result.setTextFormat(fm);
            addChild(result);
            return result;
        }
    }
}

htmlText

屬性 
htmlText:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

包含 HTML 表示方式的文字欄位內容。

Flash Player 支援下列 HTML 標籤:

標籤 說明
錨點標籤 <a> 標籤會建立超連結,並支援下列特質:
  • target:指定載入頁面所在的目標視窗名稱。 選項包括 _self_blank_parent_top_self 選項會指定目前視窗中的目前頁框、_blank 會指定新的視窗、_parent 會指定目前頁框的父輩,而 _top 則會指定目前視窗中最上層的頁框。
  • href:指定 URL 或 ActionScript link 事件。URL 可以是絕對位置,或是相對於載入頁面之 SWF 檔的位置。 URL 之絕對參照的範例為 http://www.adobe.com;相對參照的範例則為 /index.html。 絕對 URL 必須以 http:// 開頭,否則 Flash Player 或 AIR 會視為相對 URL。您可以使用 link 事件,讓連結執行 SWF 檔中的 ActionScript 函數,而不是開啟 URL。 若要指定 link 事件,請使用事件結構,而不是您的 href 特質中的 http 結構。 例如使用 href="event:myText",而不是 href="http://myURL"。當使用者按一下包含事件配置的超文字連結時,文字欄位會傳送其 text 屬性設定為 "myText" 的 link TextEvent。 接著,您可以建立於傳送 link TextEvent 時執行的 ActionScript 函數。 您也可以使用樣式表,定義錨點標籤的 a:linka:hovera:active 樣式。
粗體標籤 <b> 標籤會使文字呈現粗體。 所使用的字體必須具有粗體字樣。
斷行標籤 <br> 標籤會在文字欄位中建立斷行, 將文字欄位設為多行文字欄位,以使用這個標籤。
字體標籤 <font> 標籤會指定字體或字體清單以顯示文字。字體標籤支援下列特質:
  • color:僅支援十六進位顏色 (#FFFFFF) 值。
  • face:指定要使用的字體名稱。 如下列範例所示,您可以指定一份以逗點分隔字體名稱的清單,在此情況下,Flash Player 會選取第一種可用的字體: 如果指定的字體並未安裝在本機電腦系統上,或是未內嵌在 SWF 檔中,Flash Player 便會選取替代的字體。
  • size:指定字體大小。 您可以使用絕對像素大小,如 16 或 18;或是相對點大小,如 +2 或 -4。
影像標籤 <img> 標籤可讓您將外部影像檔 (JPEG、GIF、PNG)、SWF 檔及影片片段嵌入文字欄位中。 文字會自動排列在文字欄位中所嵌入影像的四周。 您必須將文字欄位設定為多行,才能將文字圍繞影像。

<img> 標籤支援下列特質:

  • src:指定影像檔、SWF 檔或元件庫中影片片段元件之連結識別名稱的 URL。 這個特質是必要的;其他所有特質都是選用的。 外部檔案 (JPEG、GIF、PNG 和 SWF 檔) 必須等到下載完成之後才會顯示。
  • width:所插入之影像、SWF 檔案或影片片段的寬度 (以像素為單位)。
  • height:所插入之影像、SWF 檔或影片片段的高度 (以像素為單位)。
  • align:指定文字欄位內所嵌入影像的水平對齊方式。 有效值為 leftright。 預設值為 left
  • hspace:指定環繞在影像周圍而不會顯示文字的水平空間量。 預設值為 8。
  • vspace:指定環繞在影像周圍而不會顯示文字的垂直空間量。 預設值為 8。
  • id:指定含有內嵌影像檔、SWF 檔或影片片段之影片片段實體 (由 Flash Player 建立) 的名稱。 這讓您得以使用 ActionScript 控制內嵌內容。
  • checkPolicyFile:指定 Flash Player 檢查伺服器 (與影像的網域有關聯) 上的 URL 原則檔。如果原則檔存在,檔案中所列出網域內的 SWF 檔即可存取載入影像的資料,例如呼叫 BitmapData.draw() 方法,並以此影像做為 source 參數。如需安全性詳細資訊,請參閱「Flash Player 開發人員中心」主題:安全性

Flash 會以完整大小來顯示文字欄位中所嵌入的媒體。 若要指定內嵌的媒體尺寸,請使用 <img> 標籤的 heightwidth 特質。

一般而言,嵌入在文字欄位中的影像,會顯示在 <img> 標籤之後的下一行中。 然而,如果 <img> 標籤是文字欄位中的第一個字元,影像便會出現在文字欄位的第一行上。

對於應用程式安全執行程序中的 AIR 內容,AIR 會忽略 ActionScript TextField 物件中 HTML 內容的 img 標籤。這可避免遭受潛在的網路釣魚攻擊。

斜體標籤 <i> 標籤會將加上標籤的文字以斜體顯示。 所使用的字體必須具有斜體字樣。
清單項目標籤 <li> 標籤會在標籤內的文字之前加上項目符號。 注意:由於 Flash Player 與 AIR 無法辨識編號清單和項目清單標籤 (<ol><ul>),這些標籤不會修改清單的顯示方式。所有的清單都沒有順序,而且所有的清單項目都會使用項目符號。
段落標籤 <p> 標籤會建立新的段落。 文字欄位必須設為多行文字欄位,才能使用這個標籤。<p> 標籤支援下列特質:
  • align:指定段落內文字的對齊方式;有效值為 leftrightjustifycenter
  • class:指定由 flash.text.StyleSheet 物件定義的 CSS 樣式類別。
Span 標籤 <span> 標籤只能用於 CSS 文字樣式 它支援以下特質:
  • class:指定由 flash.text.StyleSheet 物件定義的 CSS 樣式類別。
文字格式標籤

<textformat> 標籤可讓您在文字欄位內使用 TextFormat 類別的段落格式屬性之子集,包括行距、縮排、邊界及定位停駐點。 您可以將 <textformat> 標籤與內建的 HTML 標籤組合使用。

<textformat> 標籤具有下列特質:

  • blockindent:以點為單位指定區塊縮排;對應於 TextFormat.blockIndent
  • indent:指定段落中從左方邊界到第一個字元的縮排,對應於 TextFormat.indent。 正值與負值均可接受。
  • leading:指定行與行之間的距離 (垂直間距),對應於 TextFormat.leading。 正值與負值均可接受。
  • leftmargin:以點為單位指定段落的左邊界;對應於 TextFormat.leftMargin
  • rightmargin:以點為單位指定段落的右邊界,對應於 TextFormat.rightMargin
  • tabstops:指定自訂定位停駐點為非負值整數的陣列,對應於 TextFormat.tabStops
底線標籤 <u> 標籤會為標籤內的文字加上底線。

Flash Player 和 AIR 支援下列 HTML 實體:

實體 說明
&lt; < (小於)
&gt; > (大於)
&amp; & (&符號)
&quot; " (雙引號)
&apos; ' (所有格、單引號)

Flash Player 和 AIR 也明確支援字元碼,如 &#38; (ASCII 的 & 符號) 及 &#x20AC; (Unicode 的 € 符號)。



實作
    public function get htmlText():String
    public function set htmlText(value:String):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會建立 TextField tf1,並將一個 HTML 格式化字串指定給它的 text 屬性。 Flash Player 在追蹤它的 htmlText 屬性後,會自動為輸出的 HTML 格式化字串加上其他的標籤 (如 <P> 和 <FONT>)。 在追蹤 text 屬性的值後,會顯示還沒有加上 HTML 標籤的未格式化字串。

為了方便對照,在另一個 TextField 物件 tf2 上也會執行相同的步驟。此外,在設定它的 htmlText 屬性之前,會先將 StyleSheet 物件指定給 tf2styleSheet 屬性。 Flash Player 在追蹤 htmlText 屬性之後,不會為它加上其他標籤,它包括的 HTML 文字和原先指定給 htmlText 屬性的 HTML 文字完全相同。

package {
    import flash.display.Sprite;
    import flash.text.StyleSheet;
    import flash.text.TextField;

    public class TextField_text extends Sprite {
        public function TextField_text() {
            var tf1:TextField = createCustomTextField(10, 10, 400, 22);
            tf1.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";

            // htmlText: <P ALIGN="LEFT"><FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0"><b>Lorem ipsum dolor sit amet.</b></FONT></P>
            trace("htmlText: " + tf1.htmlText);
            // text: Lorem ipsum dolor sit amet.
            trace("text: " + tf1.text);
            
            var tf2:TextField = createCustomTextField(10, 50, 400, 22);
            tf2.styleSheet = new StyleSheet();
            tf2.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";
            // htmlText: <b>Lorem ipsum dolor sit amet.</b>
            trace("htmlText: " + tf2.htmlText);
            // text: Lorem ipsum dolor sit amet.
            trace("text: " + tf2.text);
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            addChild(result);
            return result;
        }
    }
}

length

屬性 
length:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字欄位中的字元數。 像是定位點字元 (\t) 這類字元也算是一個字元。



實作
    public function get length():int

maxChars

屬性 
maxChars:int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字欄位可以包含的最大字元數,也就是使用者可輸入的字元數。 程式碼可以插入比 maxChars 允許還多的文字;maxChars 屬性僅會指出使用者可輸入多少文字。 如果此屬性的值是 0,使用者即可輸入無限數量的文字。

預設值為 0。



實作
    public function get maxChars():int
    public function set maxChars(value:int):void

maxScrollH

屬性 
maxScrollH:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

scrollH 的最大值。



實作
    public function get maxScrollH():int

相關 API 元素

maxScrollV

屬性 
maxScrollV:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

scrollV 的最大值。



實作
    public function get maxScrollV():int

相關 API 元素

mouseWheelEnabled

屬性 
mouseWheelEnabled:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9

Boolean 值,指出當使用者按一下文字欄位並滾動滑鼠滾輪時,Flash Player 是否會自動捲動多行文字欄位。根據預設,這個值為 true。 如果想要防止滑鼠滾輪捲動文字欄位,或實作您自己的文字欄位捲動,這個屬性就會很有用。



實作
    public function get mouseWheelEnabled():Boolean
    public function set mouseWheelEnabled(value:Boolean):void

multiline

屬性 
multiline:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指出欄位是否為多行文字欄位。如果其值是 true,文字欄位就是多行;如果是 false,則表示文字欄位是單行文字欄位。在 TextFieldType.INPUT 類型的欄位中,multiline 值會決定 Enter 鍵是否會建立新行 (如果為 false 值,則會忽略 Enter 鍵)。如果您將文字貼至 multiline 值為 falseTextField,則會從文字中去除新行字元。

預設值為 false。



實作
    public function get multiline():Boolean
    public function set multiline(value:Boolean):void

相關 API 元素

numLines

屬性 
numLines:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會定義多行文字欄位中的文字行數。 如果 wordWrap 屬性設定為 true,行數便會在文字換行時增加。



實作
    public function get numLines():int

相關 API 元素

restrict

屬性 
restrict:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指出使用者能夠輸入文字欄位中的字元組。 如果 restrict 屬性的值是 null,您就可以輸入任何字元。 如果 restrict 屬性的值是空字串,您就不能輸入任何字元。 如果 restrict 屬性的值是字元組成的字串,您只能在文字欄位內輸入此字串中的字元。 會由左向右掃描這個字串。 您可以使用連字符號 (-) 字元指定範圍。 只會限制使用者互動;Script 可以將任何文字放入文字欄位中。這個屬性不會與「屬性」檢測器中的「嵌入字體」選項同步化。

如果字串以跳脫字元 (^) 開始,在初始時便會接受所有的字元,字串中的後續字元則會排除在接受的字元組之外。 如果該字串不是以跳脫字元 (^) 開始,在初始時便不會接受任何字元,並且字串中的後續字元都會包含在接受的字元組內。

下列範例只允許在文字欄位中輸入大寫字元、空格和數字:

     my_txt.restrict = "A-Z 0-9";
     

下列範例包含所有字元,但排除小寫字母:

     my_txt.restrict = "^a-z";
     

您可以使用反斜線來逐字輸入 ^ 或 -。 接受的反斜線序列為 \-、\^ 或 \\。 反斜線必須是字串中的實際字元,因此當您在 ActionScript 中指定它時,就必須使用雙反斜線。 例如,以下的程式碼只包含破折號 (-) 和跳脫字元 (^):

     my_txt.restrict = "\\-\\^";
     

^ 可以在字串中的任何一處使用,用以切換包含的字元及排除的字元。下列程式碼只包含大寫字母,但排除大寫字母 Q:

     my_txt.restrict = "A-Z^Q";
     

您可以使用 \u 跳脫序列來建構 restrict 字串。下列程式碼只包含從 ASCII 32 (空格) 到 ASCII 126 ("~" 符號) 的字元。

     my_txt.restrict = "\u0020-\u007E";
     

預設值為 null。



實作
    public function get restrict():String
    public function set restrict(value:String):void

scrollH

屬性 
scrollH:int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

目前的水平捲動位置。 如果 scrollH 屬性是 0,文字便不會水平捲動。 這個屬性值是代表水平位置 (以像素為單位) 的整數。

水平捲動的單位是像素,垂直捲動的單位則是字行。 水平捲動是以像素為單位來測量,因為一般使用的字體多數都依比例調整間距。也就是說,字元可以有不同的寬度。 由於使用者通常希望看到的是完整的字行,而非部分的字行,所以 Flash Player 會逐行執行垂直捲動。 即使一個字行使用多種字體,該字行的高度也會調整以配合使用的最大字體。

注意: scrollH 屬性是從 0 開始,不像 scrollV 垂直捲動屬性是從 1 開始。



實作
    public function get scrollH():int
    public function set scrollH(value:int):void

相關 API 元素

scrollV

屬性 
scrollV:int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字欄位中文字的垂直位置。 scrollV 屬性有助於在長篇中將使用者引導至特定的段落,或是建立捲動的文字欄位。

垂直捲動的單位是字行,水平捲動的單位則是像素。 如果顯示的第一個字行是文字欄位中的第一個字行,scrollV 便會設定為 1 (而非 0)。 水平捲動是以像素為單位來測量,因為多數字體都是依比例調整間距。也就是說,字元可以有不同的寬度。 由於使用者通常希望看到的是完整的字行,而非部分的字行,所以 Flash 會逐行執行垂直捲動。 即使一行文字上有多種字體,行的高度也會調整成符合所使用的最大字體。



實作
    public function get scrollV():int
    public function set scrollV(value:int):void

相關 API 元素

selectable

屬性 
selectable:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指出文字欄位是否可選取的 Boolean 值。 true 值表示文字是可選取的。 selectable 屬性會控制是否可選取 (而非編輯) 文字欄位。 動態的文字欄位就算不能編輯一樣可以選取。 如果無法選取動態文字欄位,使用者便無法選取其文字。

如果 selectable 設定為 false,文字欄位中的文字就不會回應滑鼠或鍵盤上的選取命令,而且也無法以「複製」命令複製文字。 如果 selectable 設定為 true,即可以滑鼠或鍵盤選取文字欄位中的文字,並且能以「複製」命令複製文字。 就算文字欄位是動態文字欄位而不是輸入文字欄位,您仍然可以依這種方式選取文字。

預設值為 true。



實作
    public function get selectable():Boolean
    public function set selectable(value:Boolean):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會建立兩個動態文字欄位:selectable 屬性設定為 true 的文字欄位,以及 selectable 屬性設定為 false 的另一個文字欄位。當您使用這個範例時,請嘗試使用滑鼠或鍵盤選取這些欄位中的文字。
package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    public class selectableExample extends Sprite
    {
        public function selectableExample()
        {
    var tf1:TextField = createCustomTextField(10, 10);
    tf1.text="This text can be selected";
    tf1.selectable=true;

    var tf2:TextField = createCustomTextField(10, 30);
    tf2.text="This text cannot be selected";
    tf2.selectable=false;
        }

        private function createCustomTextField(x:Number, y:Number):TextField 
       {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.autoSize=TextFieldAutoSize.LEFT;
            addChild(result);
            return result;
        }
    }
}

selectionBeginIndex

屬性 
selectionBeginIndex:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

目前選取範圍中,第一個字元的字元索引值 (從零開始)。 例如,第一個字元是 0,第二個字元是 1,依此類推。 如果沒有選取文字,此屬性便會是 caretIndex 的值。



實作
    public function get selectionBeginIndex():int

相關 API 元素


範例  ( 如何使用本範例 )
此範例會建立 TextField 實體並填入文字。 然後指派事件偵聽程式,如此當使用者按一下此 TextField 時,就會呼叫 printCursorPosition 方法。 之後就會輸出 caretIndexselectionBeginIndexselectionEndIndex 屬性的值。

請執行此範例,並嘗試在 TextField 中按一下以選取文字。 然後,在欄位中按一下而不選取文字。 當您按一下文字但不做選取動作時,caretIndex 屬性表示要放入插入點的位置,而 selectionBeginIndexselectionEndIndex 屬性則等於 caretIndex 屬性值。

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class TextField_caretIndex extends Sprite {
        public function TextField_caretIndex() {
            var tf:TextField = createCustomTextField(10, 10, 100, 100);
            tf.wordWrap = true;
            tf.type = TextFieldType.INPUT;
            tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
            tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
        }

        private function printCursorPosition(event:MouseEvent):void {
            var tf:TextField = TextField(event.target);
            trace("caretIndex:", tf.caretIndex);
            trace("selectionBeginIndex:", tf.selectionBeginIndex);
            trace("selectionEndIndex:", tf.selectionEndIndex);
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            addChild(result);
            return result;
        }
    }
}

selectionEndIndex

屬性 
selectionEndIndex:int  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

目前選取範圍中,最後一個字元的字元索引值 (從零開始)。 例如,第一個字元是 0,第二個字元是 1,依此類推。 如果沒有選取文字,此屬性便會是 caretIndex 的值。



實作
    public function get selectionEndIndex():int

相關 API 元素


範例  ( 如何使用本範例 )
此範例會建立 TextField 實體並填入文字。 然後指派事件偵聽程式,如此當使用者按一下此 TextField 時,就會呼叫 printCursorPosition 方法。 之後就會輸出 caretIndexselectionBeginIndexselectionEndIndex 屬性的值。

請執行此範例,並嘗試在 TextField 中按一下以選取文字。 然後,在欄位中按一下而不選取文字。 當您按一下文字但不做選取動作時,caretIndex 屬性表示要放入插入點的位置,而 selectionBeginIndexselectionEndIndex 屬性則等於 caretIndex 屬性值。

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class TextField_caretIndex extends Sprite {
        public function TextField_caretIndex() {
            var tf:TextField = createCustomTextField(10, 10, 100, 100);
            tf.wordWrap = true;
            tf.type = TextFieldType.INPUT;
            tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
            tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
        }

        private function printCursorPosition(event:MouseEvent):void {
            var tf:TextField = TextField(event.target);
            trace("caretIndex:", tf.caretIndex);
            trace("selectionBeginIndex:", tf.selectionBeginIndex);
            trace("selectionEndIndex:", tf.selectionEndIndex);
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            addChild(result);
            return result;
        }
    }
}

sharpness

屬性 
sharpness:Number

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9

在這個文字欄位中,文字邊緣的清晰度。只有在文字欄位的 flash.text.AntiAliasType 屬性設定為 flash.text.AntiAliasType.ADVANCED 時,才會套用這個屬性。 sharpness 的範圍是從 -400 到 400 之間的數字。 如果嘗試將 sharpness 設定為範圍外的值,Flash 會將屬性設定為離範圍內最近的值 (不是 -400 就是 400)。

預設值為 0。



實作
    public function get sharpness():Number
    public function set sharpness(value:Number):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會示範為 TextField 物件變更 sharpness 屬性的作用。您需要內嵌此字體,並將 antiAliasType 屬性設定為 ADVANCED
package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.AntiAliasType;
    import flash.text.GridFitType;
    import flash.text.TextFormat;

    public class sharpnessExample extends Sprite
    {
        public function sharpnessExample()
        {
    var format1:TextFormat = new TextFormat();
    format1.font="Arial";
    format1.size=24;
    var lTxt:String = "The quick brown fox";

    var tf1:TextField=createCustomTextField(0,lTxt,format1,-400);
    var tf2:TextField=createCustomTextField(30,lTxt,format1,0);
    var tf3:TextField=createCustomTextField(60,lTxt,format1,400);
        }

        private function createCustomTextField(y:Number,fldTxt:String,format:TextFormat,fldSharpness:Number):TextField 
       {
            var result:TextField = new TextField();
            result.y=y;
            result.text=fldTxt;
            result.embedFonts=true;
            result.autoSize=TextFieldAutoSize.LEFT;
            result.antiAliasType=AntiAliasType.ADVANCED;
            result.gridFitType=GridFitType.PIXEL;
            result.sharpness=fldSharpness;
            result..setTextFormat(format);
            addChild(result);
            return result;
        }
    }
}

styleSheet

屬性 
styleSheet:StyleSheet

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

將樣式表附加至文字欄位。 如需建立樣式表的資訊,請參閱 StyleSheet 類別和「ActionScript 3.0 開發人員指南」。

您隨時都能變更與文字欄位有關聯的樣式表。 如果您變更使用中的樣式表,便會以新的樣式表重繪文字欄位。 您可以將樣式表設定為 nullundefined 以移除樣式表。 使用的樣式表若被移除,文字欄位會在沒有樣式表的情況下重新繪製。

注意:如果移除樣式表,TextField.textTextField.htmlText 的內容都會變更,以便將該樣式表先前套用的格式納入。 若要保留不含格式的原始 TextField.htmlText 內容,請先將該值儲存在變數中,再移除樣式表。



實作
    public function get styleSheet():StyleSheet
    public function set styleSheet(value:StyleSheet):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會定義簡單 StyleSheet 物件,並將它指定給具有 HTML 內容的文字欄位。設定內容之前,請先設定 stylesheet 屬性。
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.StyleSheet;

    public class TextStylesheetExample extends Sprite {
        var myLabel:TextField = new TextField();
        var labelText:String = "Hello world.";
        var newStyle:StyleSheet = new StyleSheet();

        public function TextStylesheetExample()
       {
            var styleObj:Object = new Object();
            styleObj.fontWeight = "bold";
            styleObj.color = "#660066";
            newStyle.setStyle(".defStyle", styleObj);

            myLabel.styleSheet=newStyle;
            myLabel.htmlText=labelText;
            addChild(myLabel);
        }
    }
}

text

屬性 
text:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

做為文字欄位中目前文字的字串。 字行是由歸位字元 ('\r',ASCII 13) 加以區隔。 這個屬性包含文字欄位中不含 HTML 標籤的未格式化文字。

若要取得 HTML 格式的文字,請使用 htmlText 屬性。

注意:如果樣式表套用到文字欄位,text 屬性的內容將會解譯為 HTML。



實作
    public function get text():String
    public function set text(value:String):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會建立 TextField tf1,並將一個 HTML 格式化字串指定給它的 text 屬性。 Flash Player 在追蹤它的 htmlText 屬性後,會自動為輸出的 HTML 格式化字串加上其他的標籤 (如 <P> 和 <FONT>)。 在追蹤 text 屬性的值後,會顯示還沒有加上 HTML 標籤的未格式化字串。

為了方便對照,在另一個 TextField 物件 tf2 上也會執行相同的步驟。此外,在設定它的 htmlText 屬性之前,會先將 StyleSheet 物件指定給 tf2styleSheet 屬性。 Flash Player 在追蹤 htmlText 屬性之後,不會為它加上其他標籤,它包括的 HTML 文字和原先指定給 htmlText 屬性的 HTML 文字完全相同。

package {
    import flash.display.Sprite;
    import flash.text.StyleSheet;
    import flash.text.TextField;

    public class TextField_text extends Sprite {
        public function TextField_text() {
            var tf1:TextField = createCustomTextField(10, 10, 400, 22);
            tf1.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";

            // htmlText: <P ALIGN="LEFT"><FONT FACE="Times New Roman" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0"><b>Lorem ipsum dolor sit amet.</b></FONT></P>
            trace("htmlText: " + tf1.htmlText);
            // text: Lorem ipsum dolor sit amet.
            trace("text: " + tf1.text);
            
            var tf2:TextField = createCustomTextField(10, 50, 400, 22);
            tf2.styleSheet = new StyleSheet();
            tf2.htmlText = "<b>Lorem ipsum dolor sit amet.</b>";
            // htmlText: <b>Lorem ipsum dolor sit amet.</b>
            trace("htmlText: " + tf2.htmlText);
            // text: Lorem ipsum dolor sit amet.
            trace("text: " + tf2.text);
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            addChild(result);
            return result;
        }
    }
}

textColor

屬性 
textColor:uint

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字欄位中文字的顏色,以十六進位格式表示。 16 進位顏色系統使用六位數來代表顏色值。 每位數字都具有 16 種可能的值或字元。字元的範圍從 0 到 9,並從 A 到 F。例如,黑色是 0x000000;白色是 0xFFFFFF

預設值為 0 (0x000000)。



實作
    public function get textColor():uint
    public function set textColor(value:uint):void

範例  ( 如何使用本範例 )
下列 ActionScript 會建立 TextField 物件並將它的 textColor 屬性變更為紅色 (0xFF0000)。
package {
    import flash.display.Sprite;
    import flash.text.TextField;

    public class TextField_textColor extends Sprite {
        public function TextField_textColor() {
            var tf:TextField = createCustomTextField(10, 10, 100, 300);
            tf.text = "This will be red text";
            tf.textColor = 0xFF0000;            
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            addChild(result);
            return result;
        }
    }
}

textHeight

屬性 
textHeight:Number  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字的高度,以像素為單位。



實作
    public function get textHeight():Number

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會建立 TextField 物件,並且會將其指定為文字。trace 陳述式會顯示 textWidthtextHeight 屬性的值。為了方便對照,同時也會顯示 widthheight 屬性(請注意您看到的 textHeighttextWidth 值也許會與您電腦上所使用的字體不同)。
package {
    import flash.display.Sprite;
    import flash.text.TextField;

    public class TextField_textHeight extends Sprite {
        public function TextField_textHeight() {
            var tf:TextField = createCustomTextField(10, 10, 100, 150);
            tf.text = "Sample text";
            
            trace("textWidth: " + tf.textWidth); // textWidth: 55.75
            trace("textHeight: " + tf.textHeight); // textHeight: 13.450000000000001
            trace("width: " + tf.width); // width: 100
            trace("height: " + tf.height); // height: 150
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            result.border = true;
            result.background = true;
            addChild(result);
            return result;
        }
    }
}

textInteractionMode

屬性 
textInteractionMode:String  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 11, Flash Lite 4

互動模式屬性,預設值為 TextInteractionMode.NORMAL。在行動平台上,一般模式是指文字可捲動但不能選取的模式。您可以在文字欄位上透過內建的快顯選單,切換到可選取的模式。在桌上型電腦上,一般模式是指文字可捲動且可以選取的模式。



實作
    public function get textInteractionMode():String

textWidth

屬性 
textWidth:Number  [唯讀]

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字的寬度,以像素為單位。



實作
    public function get textWidth():Number

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會建立 TextField 物件,並且會將其指定為文字。trace 陳述式會顯示 textWidthtextHeight 屬性的值。為了方便對照,同時也會顯示 widthheight 屬性(請注意您看到的 textHeighttextWidth 值也許會與您電腦上所使用的字體不同)。
package {
    import flash.display.Sprite;
    import flash.text.TextField;

    public class TextField_textHeight extends Sprite {
        public function TextField_textHeight() {
            var tf:TextField = createCustomTextField(10, 10, 100, 150);
            tf.text = "Sample text";
            
            trace("textWidth: " + tf.textWidth); // textWidth: 55.75
            trace("textHeight: " + tf.textHeight); // textHeight: 13.450000000000001
            trace("width: " + tf.width); // width: 100
            trace("height: " + tf.height); // height: 150
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            result.border = true;
            result.background = true;
            addChild(result);
            return result;
        }
    }
}

thickness

屬性 
thickness:Number

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9

在這個文字欄位中,字符邊緣的粗細。 只有在 flash.text.AntiAliasType 設定為 flash.text.AntiAliasType.ADVANCED 才會套用這個屬性。

thickness 的範圍是從 -200 到 200 之間的數字。 如果嘗試將thickness 設定為範圍外的值,Flash 會將屬性設定為離範圍內最近的值 (不是 -200 就是 200)。

預設值為 0。



實作
    public function get thickness():Number
    public function set thickness(value:Number):void

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會示範為 TextField 物件變更 thickness 屬性的作用。您需要內嵌此字體,並將 antiAliasType 屬性設定為 ADVANCED
package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.AntiAliasType;
    import flash.text.GridFitType;
    import flash.text.TextFormat;

    public class thicknessExample extends Sprite
    {
        public function thicknessExample()
        {
    var format1:TextFormat = new TextFormat();
    format1.font="Arial";
    format1.size=24;
    var lTxt:String = "The quick brown fox";

    var tf1:TextField=createCustomTextField(0,lTxt,format1,-200);
    var tf2:TextField=createCustomTextField(30,lTxt,format1,0);
    var tf3:TextField=createCustomTextField(60,lTxt,format1,200);
        }

        private function createCustomTextField(y:Number,fldTxt:String,format:TextFormat,fldThickness:Number):TextField 
       {
            var result:TextField = new TextField();
            result.y=y;
            result.text=fldTxt;
            result.embedFonts=true;
            result.autoSize=TextFieldAutoSize.LEFT;
            result.antiAliasType=AntiAliasType.ADVANCED;
            result.gridFitType=GridFitType.PIXEL;
            result.thickness=fldThickness;
            result.setTextFormat(format);
            addChild(result);
            return result;
        }
    }
}

type

屬性 
type:String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

文字欄位的類型。 可以是下列其中一個 TextFieldType 常數:TextFieldType.DYNAMIC,會指定使用者無法編輯的動態文字欄位;或是 TextFieldType.INPUT,會指定使用者可以編輯的輸入文字欄位。

預設值為 dynamic。



實作
    public function get type():String
    public function set type(value:String):void

擲回值
ArgumentError — 指定的 type 不是 flash.text.TextFieldType 的成員。

相關 API 元素


範例  ( 如何使用本範例 )
下列範例會建立兩個文字欄位:tfDynamictfInput。 兩個文字欄位中都會輸入文字。 然而,tfDynamictype 屬性已經設定為 TextFieldType.DYNAMIC,而 tfInputtype 屬性則已經設定為 TextFieldType.INPUT,因此使用者可以修改 tfInput 中的文字,但只能檢視 tfDynamic 中的文字。
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;

    public class TextField_type extends Sprite {
        public function TextField_type() {
            var tfDynamic:TextField = createCustomTextField(10, 10, 100, 20);
            tfDynamic.type = TextFieldType.DYNAMIC;
            tfDynamic.text = "hello";

            var tfInput:TextField = createCustomTextField(10, 45, 100, 20);
            tfInput.type = TextFieldType.INPUT;
            tfInput.text = "world";
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            result.background = true;
            result.border = true;
            addChild(result);
            return result;
        }
    }
}

useRichTextClipboard

屬性 
useRichTextClipboard:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9

會指定文字格式是否隨著文字一起複製和貼上。 如果設定為 true,則當您在文字欄位之間複製和貼上文字時,Flash Player 也會複製和貼上格式 (如對齊方式、粗體及斜體)。複製和貼上程序中的原始與目標文字欄位,都必須將 useRichTextClipboard 設定為 true。 預設值是 false



實作
    public function get useRichTextClipboard():Boolean
    public function set useRichTextClipboard(value:Boolean):void

範例  ( 如何使用本範例 )
此範例會建立輸入文字欄位 (tf1) 及兩個動態文字欄位 (tf2tf3)。程式碼會針對每個動態文字欄位指定 TextFormat 物件 (Courier 粗體字)。tf2 文字欄位具有設為 falseuseRichTextClipboard 屬性。tf3 文字欄位具有設為 trueuseRichTextClipboard 屬性。當您複製 tf2 文字欄位中的文字,然後貼至 tf1 文字欄位時,貼上的文字不包括格式。當您複製 tf3 文字欄位 (useRichTextClipboard 設為 true) 中的文字,並將它貼到 tf1 文字欄位時,貼上的文字包括格式。
package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;

    public class useRichTextClipboard extends Sprite
    {
        public function useRichTextClipboard()
        {
    var format1:TextFormat = new TextFormat();
    format1.font="Courier";
    format1.bold=true;

    var tf1:TextField = createCustomTextField(10, 10, 200, 20);
    tf1.type=TextFieldType.INPUT;
    tf1.useRichTextClipboard=true;

    var tf2:TextField = createCustomTextField(220, 10, 200, 20);
    tf2.text="1.Text loses format";
    tf2.setTextFormat(format1);
    tf2.useRichTextClipboard=false;

    var tf3:TextField = createCustomTextField(220, 50, 200, 20);
    tf3.text="2.Text includes format";
    tf3.setTextFormat(format1);
    tf3.useRichTextClipboard=true;
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField 
       {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            result.background = true;
            result.border = true;
            addChild(result);
            return result;
        }
    }
}

wordWrap

屬性 
wordWrap:Boolean

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指出文字欄位是否具有文字換行功能的 Boolean 值。 如果 wordWrap 的值是 true,文字欄位便有文字換行;如果這個值是 false,文字欄位就沒有文字換行。 預設值是 false



實作
    public function get wordWrap():Boolean
    public function set wordWrap(value:Boolean):void

範例  ( 如何使用本範例 )
這個範例會說明將 wordWrap 屬性設定為 true 以及將它設定為 false 兩者之間的差異。 這裡會建立兩個內容大過其寬度的 TextField 實體。 第一個 (tfWrap) wordWrap 屬性是設定為 true;而第二個 (tfNoWrap) 屬性則是設定為 false
package {
    import flash.display.Sprite;
    import flash.text.TextField;

    public class TextField_wordWrap extends Sprite {
        public function TextField_wordWrap() {
            var tfWrap:TextField = createCustomTextField(10, 10, 100, 100);
            tfWrap.wordWrap = true;
            tfWrap.text = "(wordWrap = true):\nThis is very long text that will certainly extend beyond the width of this text field";

            var tfNoWrap:TextField = createCustomTextField(10, 150, 100, 100);
            tfNoWrap.wordWrap = false;
            tfNoWrap.text = "(wordWrap = false):\nThis is very long text that will certainly extend beyond the width of this text field";
        }

        private function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            result.background = true;
            result.border = true;
            addChild(result);
            return result;
        }
    }
}
建構函式詳細資料

TextField

()建構函式
public function TextField()

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會建立新的 TextField 實體。 建立 TextField 實體之後,請呼叫父輩 DisplayObjectContainer 物件的 addChild()addChildAt() 方法,將 TextField 實體新增至顯示清單。

文字欄位的預設大小為 100 x 100 像素。


範例  ( 如何使用本範例 )

以下範例顯示您如何設定文字欄位物件的類型屬性為 TextFieldType.INPUT 常數,以在 ActionScript 3.0 中動態建立輸入的 TextField 物件。範例由 ActionScriptExamples.com 提供。
var theTextField:TextField = new TextField();
theTextField.type = TextFieldType.INPUT;
theTextField.border = true;
theTextField.x = 10;
theTextField.y = 10;
theTextField.multiline = true;
theTextField.wordWrap = true;
addChild(theTextField);
方法詳細資訊

appendText

()方法
public function appendText(newText:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 newText 參數所指定的字串附加到文字欄位之文字的尾端。 這個方法比使用加法指定 (+= ) text 屬性 (如 someTextField.text += moreText) 的方式更有效率,特別適用於含有大量內容的文字欄位。

參數

newText:String — 要附加至現有文字的字串。


範例  ( 如何使用本範例 )

下列範例會在非週末顯示時間,或是在週末顯示「現在是週末」的文字。 它也會計算直到某個位置的字元數,和文字欄位中的行數。

outputText 文字欄位會設定為自動符合文字大小,而且使用 autoSize 屬性以靠左對齊文字的方式調整大小。 outputText.text 屬性會寫入內容的第一行,而 appendText() 方法則會附加其餘內容 (不必從 text 屬性開始。 appendText() 方法也可以用來從頭開始附加文字)。 第二次設定 text 屬性會覆寫原始文字。 使用 += 運算子可將 text 屬性附加到內容後面。

if 陳述式會檢查日期是否為星期六 (6) 或星期日 (0)。 如果不是,toLocaleTimeString() 方法會傳回本地時間,這個時間會附加到文字欄位的內容後面。

文字欄位的 length 屬性是用來讀取直到呼叫函數之前的字元數,而 numLines 屬性則用來計算文字欄位中的行數。 請注意,空白行會算入行數中,而空白和斷行 (\n) 符號在計算行長度時也會計算在內。

  package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
 
    public class TextField_appendTextExample extends Sprite {
         
        public function TextField_appendTextExample() {
            var outputText:TextField = new TextField();
            var today:Date = new Date();
                
            outputText.x = 10;
            outputText.y = 10;
            outputText.background = true;
            outputText.autoSize = TextFieldAutoSize.LEFT;
 
            outputText.text = "WHAT TIME IS IT?" + "\n\n";
 
            if((today.day == 0) || (today.day == 6)) {
                outputText.appendText("It's the weekend.");
                outputText.appendText("\n\n");
           
            } else {
                outputText.appendText("The time is: ");
                outputText.appendText(today.toLocaleTimeString() + ".\n\n");  
            }

            outputText.appendText("Number of characters including line breaks and spaces so far: ");
            outputText.appendText(outputText.length.toString() + "\n");
            outputText.appendText("Number of lines in the outputText: ");
            outputText.appendText(outputText.numLines.toString());   

            this.addChild(outputText);
        }
    }
}

getCharBoundaries

()方法 
public function getCharBoundaries(charIndex:int):Rectangle

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會傳回做為字元之範圍框的矩形。

參數

charIndex:int — 字元的索引值 (從零開始,例如,第一個位置是 0,第二個位置是 1,依此類推)。

傳回值
Rectangle — 具有最大與最小之 xy 值 (可定義字元的範圍框) 的矩形。

相關 API 元素


範例  ( 如何使用本範例 )

下列範例使用 getCharBoundaries() 方法標記 (投射聚光燈在) 使用者選取的字元。

類別會定義即將用來在選取的每個文字四周繪製矩形的 spotlight Shape 物件。 當使用者按一下 myTextField 文字欄位時,會叫用 clickHandler() 方法。

clickHandler() 方法中,getCharIndexAtPoint() 方法會根據按一下滑鼠的 localXlocalY 座標,取得被按一下的字元索引,這個座標是相對於包含的 Sprite。 如果按一下滑鼠的點不在任何字元上,getCharIndexAtPoint() 方法會傳回 -1。 由於文字欄位可能比文字大,範例會檢查傳回的整數 (index),以確定使用者已按一下字元。 getCharBoundaries() 也使用 index 整數來取得存放字元邊界的 Rectangle 物件。 clear() 方法會清除之前顯示的任何 spotlight Shape 物件。 使用傳回的 frame 矩形的 x 和 y 座標,於字元的位置 (與 (10, 10) 座標相距某個偏移量) 產生新的矩形,其大小為字元的寬度和邊界的高度。 為了在字元上投射聚光燈,將 spotlight Shape 物件填滿黃色,並將不透明度設定 35%,讓文字可以被看見。 請注意,空白也視為一個字元。

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.geom.Rectangle;
    import flash.events.MouseEvent;
    import flash.text.TextFieldAutoSize;
    import flash.display.Shape;

    public class TextField_getCharBoundariesExample extends Sprite
    {
        private var myTextField:TextField = new TextField();    
        private var spotlight:Shape = new Shape();
        
        public function TextField_getCharBoundariesExample() {
            
            myTextField.x = 10;
            myTextField.y = 10; 
            myTextField.border = true;
            myTextField.selectable = false;
            myTextField.autoSize = TextFieldAutoSize.LEFT;
            
            myTextField.text = "Selected a character from this text by clicking on it."

            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
            
            this.addChild(myTextField);    
            this.addChild(spotlight);
         }

        private function clickHandler (e:MouseEvent):void {
            var index:int = myTextField.getCharIndexAtPoint(e.localX, e.localY);
 
            if (index != -1) {
                 var frame:Rectangle = myTextField.getCharBoundaries(index);

                spotlight.graphics.clear();    
                spotlight.graphics.beginFill(0xFFFF00, .35);
                spotlight.graphics.drawRect((frame.x + 10), (frame.y + 10), frame.width, frame.height);            
                spotlight.graphics.endFill();
            }
        } 
    }
}

getCharIndexAtPoint

()方法 
public function getCharIndexAtPoint(x:Number, y:Number):int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會在 xy 參數所指定的點,傳回字元的索引值 (從零開始)。

參數

x:Number — 字元的 x 座標。
 
y:Number — 字元的 y 座標。

傳回值
int — 字元的索引值 (從零開始,例如,第一個位置是 0,第二個位置是 1,依此類推)。如果該點不在任何字元上,則會傳回 -1。

範例  ( 如何使用本範例 )

在下列範例中,當使用者按一下字元時,該字元會反映在文字上方的另一個文字欄位中。

第一個文字欄位存放使用者即將選取的文字。 為了確定文字只是按一下,而非選取,selectable 屬性會設定為 false。 當使用者按一下 firstTextField 文字欄位時,會叫用 clickHandler() 方法。

clickHandler() 方法中,getCharIndexAtPoint() 方法會根據按一下滑鼠的 localXlocalY 座標,傳回字元的索引。 由於文字欄位可能比文字大,範例會檢查傳回的整數 (index),以確定使用者已按一下字元。 (如果按一下滑鼠的點不在字元之上,getCharIndexAtPoint() 會傳回 -1)。 滑鼠座標是用來設定新文字欄位中,即將顯示反映文字的座標。 第二個文字欄位中的字元色彩會設定為紅色。 最後,會將第二個欄位的文字設定為使用 charAt() 方法擷取而來的選取文字。 請注意,如果使用 text 屬性,而不用 appendText() 方法,將會覆寫第二個文字欄位的字元,而非附加在後面。

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.geom.Rectangle;
    import flash.events.MouseEvent;
    import flash.text.TextFieldAutoSize;
    
    public class TextField_getCharIndexAtPointExample extends Sprite {
        private var firstTextField:TextField = new TextField();    
        private var secondTextField:TextField = new TextField();
        
        public function TextField_getCharIndexAtPointExample() {

            firstTextField.x = 100;
            firstTextField.y = 100; 
            firstTextField.width = 260;
            firstTextField.height = 20;
            firstTextField.border = true;
            firstTextField.background = true;
            firstTextField.selectable = false;
            
            firstTextField.text = "Selected a character from this text by clicking on it."

            firstTextField.addEventListener(MouseEvent.CLICK, clickHandler);

            this.addChild(firstTextField);    
            this.addChild(secondTextField);
         }

        private function clickHandler (e:MouseEvent):void {
            var index:int = firstTextField.getCharIndexAtPoint(e.localX, e.localY);

            if (index != -1) {
                secondTextField.x = mouseX;
                secondTextField.y =  70;
                secondTextField.border = true;
                secondTextField.selectable = false;
                secondTextField.background = true;
                secondTextField.textColor = 0xFF0000;
                secondTextField.autoSize = TextFieldAutoSize.LEFT;
                secondTextField.text = firstTextField.text.charAt(index);    
            }
        } 
    }
}

getFirstCharInParagraph

()方法 
public function getFirstCharInParagraph(charIndex:int):int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指定字元索引,會傳回相同段落中第一個字元的索引。

參數

charIndex:int — 字元的索引值 (從零開始,例如,第一個字元是 0,第二個字元是 1,依此類推)。

傳回值
int — 相同段落中,第一個字元的索引值 (從零開始)。

擲回值
RangeError — 指定的字元索引超出範圍。

範例  ( 如何使用本範例 )

下列範例會對文字欄位內容套用段落格式設定。 當使用者按一下段落時,段落文字會靠右對齊,而當使用者再按一下段落時,它會回復原始 (預設) 格式 (靠左對齊)。

建構函式中將 myTextField 文字欄位設定為文字換行。 getTextFormat 方法會傳回文字欄位中內容第一個字元的原始格式,放在 originalFormat TextFormat 物件中。 此外,還定義了一個新的 TextFormat 物件 (newFormat),並將其 align 屬性指定為靠右對齊。 當使用者按一下文字欄位時,會叫用 clickHandler() 方法。

clickHandler() 方法中,getCharIndexAtPoint() 方法會根據按一下滑鼠的 localXlocalY 座標,傳回字元的索引。 第一個 if 陳述式會檢查使用者是否已在字元上按一下。 使用 getCharIndexAtPoint() 方法傳回的 clickIndex 整數,getFirstCharInParagraph() 方法便會傳回使用者所按一下的段落中第一個字元的索引。 段落中最後一個字元的索引計算方式,是將段落長度 (使用 getParagraphLength() 方法) 加上段落中第一個字元的索引,減去最後一個字元 (\n)。 第二個 if 陳述式檢查段落中第一個字元的格式。 如果對齊值與原始格式 (靠左對齊) 相同,就會對段落中的所有字元套用新的格式。 否則,便會將段落格式設回原始格式。 對齊以及縮排、項目、定位停駐點、左方邊界和右方邊界等格式設定都是針對段落。 請注意,使用文字換行或斷行符號時,如果未定義 setTextFormat() 方法的 endIndex 引數,則格式設定將只套用到段落的第一行。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;

    public class TextField_getFirstCharInParagraphExample extends Sprite
    {
        private var myTextField:TextField = new TextField();
        private var originalFormat:TextFormat = new TextFormat();
        private var newFormat:TextFormat = new TextFormat(); 
        
        public function TextField_getFirstCharInParagraphExample() {
            myTextField.x = 10;
            myTextField.y = 10; 
            myTextField.border = true;
            myTextField.wordWrap = true;
            myTextField.width = 300;
            myTextField.height = 300; 
            myTextField.background = true;
             
            myTextField.appendText("The TextField class is used to create display objects for "
                        + "text display and input. All dynamic and input text fields in a SWF file " 
                        + "are instances of the TextField class. You can use the TextField class "
                        + "to perform low-level text rendering. However, in Flex, you typically use "
                        + "the Label, Text, TextArea, and TextInput controls to process text. "  
                        + "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.\n\n"  
                        + "To create a text field dynamically, use the TextField constructor.\n\n"
                        + "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.\n\n");

            originalFormat = myTextField.getTextFormat(0);

            newFormat.align = TextFormatAlign.RIGHT;

            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
  
            this.addChild(myTextField);
        }

        private function clickHandler(e:MouseEvent):void {
            var clickIndex:int = myTextField.getCharIndexAtPoint(e.localX, e.localY);
                  
            if(clickIndex != -1) {
                var paragraphFirstIndex:int = myTextField.getFirstCharInParagraph(clickIndex);
                var paragraphEndIndex:int = paragraphFirstIndex + ((myTextField.getParagraphLength(clickIndex) - 1));
            
                if (myTextField.getTextFormat(paragraphFirstIndex).align == originalFormat.align) {
                     myTextField.setTextFormat(newFormat, paragraphFirstIndex, paragraphEndIndex);
                }else {
                     myTextField.setTextFormat(originalFormat, paragraphFirstIndex, paragraphEndIndex);
                }
            } 
        }
    }
}
 

getImageReference

()方法 
public function getImageReference(id:String):DisplayObject

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

對於使用 <img> 標籤新增至 HTML 格式之文字欄位的影像或 SWF 檔,傳回指定之 id 的 DisplayObject 參考。 <img> 標籤的格式如下:

   <img src = 'filename.jpg' id = 'instanceName' >

參數

id:String — 要進行比對的 id (即 <img> 標籤的 id 特質)。

傳回值
DisplayObject — 對應於影像或 SWF 檔,並在文字欄位的 <img> 標籤中,具有符合的 id 特質的顯示物件。對於從外部來源載入的媒體,這個物件會是 Loader 物件,而且一旦載入之後,媒體物件就會是 Loader 物件的子系。對於內嵌在 SWF 檔中的媒體,這會是載入的物件。如果沒有 <img> 標籤具有符合的 id,此方法便會傳回 null

相關 API 元素


範例  ( 如何使用本範例 )

在下列範例中,按一下文字欄位時,欄位中的影像會設定為 25% 不透明,並從原始旋轉方向旋轉 90 度。 接著,每按一次,影像都會繼續旋轉。

影像 (image.jpg) 會透過 HTML 包含在程式中 (這裡假設影像檔與 SWF 檔在相同目錄中)。 範例必須為 img 標籤定義 id 特質,才能使用 getImageReference() 方法存取影像。 htmlText 屬性會用來包含 HTML 格式的字串內容。 當使用者按一下 myTextField 文字欄位時,會叫用 clickHandler() 方法。

clickHandler() 方法中,getImageReference() 方法會以 DisplayObject 形式傳回影像的參考。 這個參考可用來處理影像,就像任何 DisplayObject 物件一樣。 這裡會設定 alpha (透明度) 和 rotation 屬性。 transform 屬性也可以用來存取顯示物件的矩陣、顏色轉換和像素邊界。 請注意,flash.display.DisplayObject 必須匯入。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.DisplayObject;
    
    import flash.text.TextFieldAutoSize;
    
    public class TextField_getImageReferenceExample extends Sprite
    {
        private var myTextField:TextField = new TextField();
        
        public function TextField_getImageReferenceExample()
        {
            var myText1:String = "<p>Here is an image we want to mainpulate: <img src='image.jpg' id='testimage'></p>";

            myTextField.x = 10;
            myTextField.y = 10;
            myTextField.width = 250;
            myTextField.height = 250;
            myTextField.background = true;
            myTextField.border = true;
            myTextField.border = true;
            myTextField.multiline = true;

            myTextField.htmlText = myText1;
            
            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
            
            this.addChild(myTextField);
        }
 
        private function clickHandler(e:MouseEvent):void {
            var imageRef:DisplayObject = myTextField.getImageReference("testimage");
 
            imageRef.rotation += 90;
            imageRef.x = 125;
            imageRef.y = 125;
            imageRef.alpha = 0.25;      
        }
    }
}

getLineIndexAtPoint

()方法 
public function getLineIndexAtPoint(x:Number, y:Number):int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會在 xy 參數所指定的點,傳回字行的索引值 (從零開始)。

參數

x:Number — 字行的 x 座標。
 
y:Number — 字行的 y 座標。

傳回值
int — 字行的索引值 (從零開始,例如,第一個字行是 0,第二個字行是 1,依此類推)。如果該點不在任何字行上,則會傳回 -1。

範例  ( 如何使用本範例 )

在下列範例中,當使用者選取莎士比亞十四行詩中的一行時,該行會複製 (附加) 到新的文字欄位中。

建構函式中,poem 文字欄位會設定為不換行 (因為是詩的關係)。 此外,也會使用 autoSize 屬性將文字設定為自動符合大小,而且以靠左對齊文字的方式調整大小。 poemCopy 文字欄位的位置在 poem 文字欄位底下。 當使用者按一下詩中某行時,會叫用 clickHandler() 方法。

clickHandler() 方法中,getLineIndexAtPoint() 方法會根據按一下滑鼠的 localXlocalY 座標,傳回使用者按一下的行索引位置 (由於原詩符合此文字欄位的大小,所以不必檢查 getCharIndexAtPoint() 方法擲回的超出範圍錯誤 (RangeError))。 接著會使用行索引,用 getLineText() 方法取得字串形式的行內容,再將它附加到 poemCopy 文字欄位內容後面。 複製動作可以繼續進行,但到了某個點之後,文字將會超出可檢視的 poemCopy 文字欄位範圍。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.text.TextFormat;
    import flash.text.TextFieldAutoSize;

    public class TextField_getLineIndexAtPointExample extends Sprite {
        private var poem:TextField = new TextField();
        private var poemCopy:TextField = new TextField();
        
        public function TextField_getLineIndexAtPointExample() {
            poem.border = true;
            poem.autoSize = TextFieldAutoSize.LEFT;
            poem.x = 10;
            poem.wordWrap = false;

            poemCopy.height = 250;
            poemCopy.width = 270;
            poemCopy.y = 230;
            poemCopy.x = 10;
            poemCopy.background = true;
            poemCopy.border = true;
            poemCopy.wordWrap = false;
            
            poem.appendText("Let me not to the marriage of true minds\n"
                              + "Admit impediments. love is not love\n"
                              + "Which alters when it alteration finds\n"
                              + "Or bends with the remover to remove:\n"
                              + "O no! it is an ever-fixed mark\n" 
                              + "That looks on tempests and is never shaken;\n"
                              + "It is the star to every wandering bark,\n"
                              + "Whose worth's unknown, although his height be taken.\n"
                              + "Love's not Time's fool, though rosy lips and cheeks\n"
                              + "Within his bending sickle's compass come:\n"
                              + "Love alters not with his brief hours and weeks,\n"
                              + "But bears it out even to the edge of doom.\n"
                              + "If this be error and upon me proved,\n"
                              + "I never writ, nor no man ever loved.");

           poem.addEventListener(MouseEvent.CLICK, clickHandler); 

           this.addChild(poem); 
           this.addChild(poemCopy);
        }
    
        private function clickHandler(e:MouseEvent):void {
                var index:int = poem.getLineIndexAtPoint(e.localX, e.localY);
                var s:String;

                s = poem.getLineText(index);
                poemCopy.appendText(s + "\n");
        }
    }
}

getLineIndexOfChar

()方法 
public function getLineIndexOfChar(charIndex:int):int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會傳回字行的索引值 (從零開始),該字行包含 charIndex 參數所指定的字元。

參數

charIndex:int — 字元的索引值 (從零開始,例如,第一個字元是 0,第二個字元是 1,依此類推)。

傳回值
int — 字行的索引值 (從零開始)。

擲回值
RangeError — 指定的字元索引超出範圍。

範例  ( 如何使用本範例 )

在下列範例中,getLineIndexOfChar() 方法會傳回文字欄位中第 100 和第 500 個字元的行號。

myTextField 文字欄位會定義為換行,並以靠左對齊文字的方式調整大小。 getLineIndexOfChar() 方法會傳回指定的字元索引 (100 和 500) 的行索引。 接著將這些資訊附加到段落後面。 請注意,因為行索引從 0 開始,所以要將行索引 (index) 加 1 才能取得行號。 此外,如果顯示曾經調整過大小,則行號可能變更,但這裡的資訊仍維持不變,因為方法只叫用一次。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    public class TextField_getLineIndexOfCharExample extends Sprite 
    {
        public function TextField_getLineIndexOfCharExample()
        {
            var myTextField:TextField = new TextField();
            
            myTextField.x = 10;
            myTextField.y = 10;
            myTextField.width = 200;
            myTextField.background = true;  
            myTextField.border = true;
            myTextField.wordWrap = true;
            myTextField.autoSize = TextFieldAutoSize.LEFT;

            myTextField.appendText("The TextField class is used to create display objects for "
                + "text display and input. All dynamic and input text fields in a SWF file" 
                + "are instances of the TextField class. You can use the TextField class "
                + "to perform low-level text rendering. However, in Flex, you typically use "
                + "the Label, Text, TextArea, and TextInput controls to process text. "  
                + "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.\n\n");

            var index:int = myTextField.getLineIndexOfChar(100);
            myTextField.appendText("100th character is in line: " +  (index + 1) + "\n");
            index = myTextField.getLineIndexOfChar(500);
            myTextField.appendText("500th character is in line: " + (index + 1));

            this.addChild(myTextField);
        }
    }
}

getLineLength

()方法 
public function getLineLength(lineIndex:int):int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會傳回特定文字行中的字元數。

參數

lineIndex:int — 您要取得其長度的行數。

傳回值
int — 字行中的字元數。

擲回值
RangeError — 指定的行數超出範圍。

範例  ( 如何使用本範例 )

在下列範例中,當使用者選取一行後,其行長度 (字元數) 會顯示在另一個文字欄位中。

例如,用來顯示即將計算的文字之 myTextField 文字欄位會設定為 INPUT,表示使用者可以真正變更各行,或是在行之間或最後加入行 (在最後一行結束處有一個使用斷行符號 (\n) 建立的空白行)。 用來顯示行長度計算結果的 countLines 文字欄位,會設定在 myTextField 文字欄位底下,而且其文字是無法選取的。 當使用者按一下 myTextField 文字欄位中某一行時,會叫用 clickHandler() 方法。

clickHandler() 中,getLineIndexAtPoint() 方法會使用按一下滑鼠的 localXlocalY 座標,傳回使用者按一下的行索引。 if 陳述式會檢查使用者是否已在字元上按一下。 如果是,getLineLength() 方法會使用行索引,傳回行中的字元數。 請注意,行之間的空白行包括第二個斷行符號 (\n),它算做 1 個字元,而最後一行之後那一行則算做 0。 空白也算做一個字元。 使用者可以寫入新行,或變更某行,也可以按一下某行取得該行的字元數。 如果使用文字換行,而且調整過螢幕大小,行索引可能會變更。

 package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class TextField_getLineLengthExample extends Sprite {
        private var myTextField:TextField = new TextField();
        private var countLines:TextField = new TextField();  

        public function TextField_getLineLengthExample() {
            myTextField.x = 10;
            myTextField.y = 10;
            myTextField.width = 350;
            myTextField.height = 150;
            myTextField.background = true;
            myTextField.border = true;
            myTextField.type = TextFieldType.INPUT;
            
            myTextField.appendText("Click on the lines to count its number of characters:\n\n");
            myTextField.appendText("This is a short line.\n");
            myTextField.appendText("This is a longer line than the last line.\n\n");
            myTextField.appendText("This one is even longer than the one before. It has two sentences.\n");

            this.addChild(myTextField);

            countLines.border = true;
            countLines.x = 10;
            countLines.y = 180;
            countLines.height = 30;
            countLines.width = 200;
            countLines.background = true;
            countLines.selectable = false;

           this.addChild(countLines);    

            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
        }

        private function clickHandler(e:MouseEvent):void {
            var index:int = myTextField.getLineIndexAtPoint(e.localX, e.localY);
        
            if (index != -1) {
            var lenght:int = myTextField.getLineLength(index);

            countLines.text = "Number of characters in the line is: " + lenght.toString();
            }
        }
    }
}

getLineMetrics

()方法 
public function getLineMetrics(lineIndex:int):flash.text:TextLineMetrics

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會傳回關於指定之文字行的公制字資訊。

參數

lineIndex:int — 您要取得其公制字資訊的行數。

傳回值
flash.text:TextLineMetrics — TextLineMetrics 物件。

擲回值
RangeError — 指定的行數超出範圍。

相關 API 元素


範例  ( 如何使用本範例 )

下列範例為兩個不同格式的文字行顯示一些行的對照表值。

附加的文字是從惠特曼名詩「自我之歌」(Song of Myself) 中節錄的兩行。 範例使用新的 TextFormat 物件 (newFormat) 來設定第二行的格式。 第一行則維持預設格式。 getLineMetrics() 方法會傳回特定行的 TextLineMetrics 物件 (行索引從 0 開始)。 範例使用 metrics1metrics2 TextLineMetrics 物件 (分別代表第一行和第二行),擷取和顯示各行的上緣、下緣、高度和粗細值。 結果數字會轉換成字串,但不四捨五入。 請注意,這個值是針對一整行,而不是針對特定字元。 它反映出一行的字元範圍。 例如,如果一行有不同高度格式的不同字元,將由最高的字元決定這個值。 這也表示,如果其中一個字元的格式變更,也可能會變更對照表值。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextLineMetrics;
    import flash.text.TextFieldAutoSize;
    import flash.text.AntiAliasType;
    import flash.text.TextFormat;
 
    public class TextField_getLineMetricsExample extends Sprite {

        public function TextField_getLineMetricsExample() {
            var myTextField:TextField = new TextField();
            var newFormat:TextFormat = new TextFormat(); 

            myTextField.x = 10;
            myTextField.y = 10;
            myTextField.background = true;
            myTextField.wordWrap = false;
            myTextField.autoSize = TextFieldAutoSize.LEFT;
            
            myTextField.appendText("A child said What is the grass? fetching it to me with full hands;\n");
            myTextField.appendText("How could I answer the child? I do not know what it is any more than he.\n\n");

            newFormat.size = 14;
            newFormat.font = "Arial";
            newFormat.italic = true;
            myTextField.setTextFormat(newFormat, 67, 139);
               
            var metrics1:TextLineMetrics = myTextField.getLineMetrics(0);
             
            myTextField.appendText("Metrics ascent for the line 1 is: " + metrics1.ascent.toString() + "\n");
            myTextField.appendText("Metrics descent is: " + metrics1.descent.toString() + "\n");
            myTextField.appendText("Metrics height is: " + metrics1.height.toString() + "\n"); 
            myTextField.appendText("Metrics width is: " + metrics1.width.toString() + "\n\n");

            var metrics2:TextLineMetrics = myTextField.getLineMetrics(1);
             
            myTextField.appendText("Metrics ascent for the line 2 is: " + metrics2.ascent.toString() + "\n");
            myTextField.appendText("Metrics descent is: " + metrics2.descent.toString() + "\n");
            myTextField.appendText("Metrics height is: " + metrics2.height.toString() + "\n"); 
            myTextField.appendText("Metrics width is: " + metrics2.width.toString() + "\n");

            addChild(myTextField);
        }
    }
}

getLineOffset

()方法 
public function getLineOffset(lineIndex:int):int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會傳回 lineIndex 參數所指定之字行中,第一個字元的字元索引。

參數

lineIndex:int — 字行的索引值 (從零開始,例如,第一個字行是 0,第二個字行是 1,依此類推)。

傳回值
int — 字行中第一個字元的索引值 (從零開始)。

擲回值
RangeError — 指定的行數超出範圍。

範例  ( 如何使用本範例 )

下列範例會檢查第 4 行的第一個字元,如果調整螢幕 (和文字欄位) 大小,這個字元將會變更。

myTextField 文字欄位會設定為文字換行。 countField 文字欄位會顯示第 4 行的第一個字元。 當使用者按一下 myTextField 文字欄位時,會叫用 clickHandler() 方法。

clickHandler() 方法中,getLineOffset() 方法會傳送行索引 3 (這是文字的第四行) 中第一個字元的索引 (第一行的索引為 0)。 範例使用 charAt() 方法,用第四行第一個字元的索引取得字元。 使用 countField 文字欄位的 text 屬性,以這個資訊更新 countField 文字欄位內容。 使用 countField.text 屬性,表示每按一下都會覆寫 countField 文字欄位的內容。 如果使用者調整顯示大小,內容將換行,所以第 4 行的第一個字元可能會改變。 只要再按一下 myTextField 欄位,countField 文字欄位的內容就會更新為第 4 行新的第一個字元。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.MouseEvent;

    public class TextField_getLineOffsetExample extends Sprite {
        private var myTextField:TextField = new TextField();
        private var countField:TextField = new TextField();
        
        public function TextField_getLineOffsetExample() {
            myTextField.x = 10;
            myTextField.y = 10;
            myTextField.width = 150;
            myTextField.height = 300;
            myTextField.background = true;
            myTextField.border = true;
            myTextField.wordWrap = true;

            countField.height = 20;
            countField.width = 200;
            countField.x = 10;
            countField.y = 320;
            countField.selectable = false;
            
            myTextField.appendText("The TextField class is used to create display objects for "
                        + "text display and input. All dynamic and input text fields in a SWF file " 
                        + "are instances of the TextField class. You can use the TextField class "
                        + "to perform low-level text rendering. However, in Flex, you typically use "
                        + "the Label, Text, TextArea, and TextInput controls to process text. "  
                        + "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.");

            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
        
            this.addChild(myTextField);
            this.addChild(countField);
        }
    
            private function clickHandler(e:MouseEvent):void {
                var c:String;
                var index:int;
                
                index = myTextField.getLineOffset(3);
                c = myTextField.text.charAt(index);
                countField.text = "The first character of line 4 is: " + c;
            }
    }
}

getLineText

()方法 
public function getLineText(lineIndex:int):String

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會傳回 lineIndex 參數所指定之字行的文字。

參數

lineIndex:int — 字行的索引值 (從零開始,例如,第一個字行是 0,第二個字行是 1,依此類推)。

傳回值
String — 指定之字行所包含的文字字串。

擲回值
RangeError — 指定的行數超出範圍。

範例  ( 如何使用本範例 )

下列範例會尋找莎士比亞十四行詩中出現的每一個 "love" 字,並顯示出來。

poem 文字欄位會設定為自動符合文字大小,而且以靠左對齊文字的方式調整大小。 wordWrap 屬性設定為 false,所以詩中各行不會換行,不過通常在使用 autoSize 屬性的情況下,這應該不是問題。 for 迴圈會使用文字欄位的 numLines 屬性,循環執行十四行詩的每一行。 getLineText() 方法會以字串形式傳回行的內容 (請注意,numLines 屬性會傳回從第 1 行開始的行號,而 getLineText() 方法的行號則從 0 開始)。 使用規則運算式樣式 (/love/i),if 陳述式會尋找這個單字大寫或小寫的任何子字串。 如果找到樣式,search 方法會傳回第一個相符子字串的索引,否則傳回 -1 (如果找不到)。 接著,會將找到 "love" 那一行的行號 ((i + 1)) 放在 lineResult 字串中。 string 方法會將數字引數 ((i + 1)) 轉換成字串,前提是必須要有另一個字串 (" ") 引數。 搜尋結果行將包含有 "loved" 或 "Love's" 這些字的每一行。如果在 for 迴圈前附加字串 "Love was found in lines:",則這一行裡的 "Love" 字也會包含在內。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
 
    public class TextField_getLineTextExample extends Sprite {
           
        public function TextField_getLineTextExample() {
           var poem:TextField = new TextField();
           var lineResult:String = ""; 
           var pattern:RegExp = /love/i;

            poem.x = 10;
            poem.y = 10;
            poem.background = true;
            poem.wordWrap = false;
            poem.autoSize = TextFieldAutoSize.LEFT;
            
            poem.text = "Let me not to the marriage of true minds\n"
                              + "Admit impediments. love is not love\n"
                              + "Which alters when it alteration finds\n"
                              + "Or bends with the remover to remove:\n"
                              + "O no! it is an ever-fixed mark\n" 
                              + "That looks on tempests and is never shaken;\n"
                              + "It is the star to every wandering bark,\n"
                              + "Whose worth's unknown, although his height be taken.\n"
                              + "Love's not Time's fool, though rosy lips and cheeks\n"
                              + "Within his bending sickle's compass come:\n"
                              + "Love alters not with his brief hours and weeks,\n"
                              + "But bears it out even to the edge of doom.\n"
                              + "If this be error and upon me proved,\n"
                              + "I never writ, nor no man ever loved.\n\n";

            for (var i:int = 0; i < poem.numLines; i++) {

                var s:String = poem.getLineText(i);
                        
                if(s.search(pattern) != -1) {
                    lineResult += (i + 1) + " ";
                }
            }

            poem.appendText("Love was found in lines: " + lineResult);
             
            this.addChild(poem);                      
        }
    }
}

getParagraphLength

()方法 
public function getParagraphLength(charIndex:int):int

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

指定字元索引,會傳回包含指定之字元的段落長度。 這個長度是相對於段落中的第一個字元 (與 getFirstCharInParagraph() 傳回的相同) 而言,而非傳入的字元索引。

參數

charIndex:int — 字元的索引值 (從零開始,例如,第一個字元是 0,第二個字元是 1,依此類推)。

傳回值
int — 會傳回段落中的字元數。

擲回值
RangeError — 指定的字元索引超出範圍。

相關 API 元素


範例  ( 如何使用本範例 )

在下列範例中,當使用者選取段落時,段落的長度和段落中的 "s" 字元數會顯示在另一個文字欄位中。

myTextField 文字欄位會顯示使用者即將選取的段落。 當使用者按一下文字欄位時,會傳送 MouseEvent.CLICK 事件,並呼叫 clickHandler() 方法。 段落長度和 "s" 字元數會顯示在 countField 文字欄位中,這個欄位的位置在 myTextField 文字欄位底下。

clickHandler() 方法中,getCharIndexAtPoint() 方法會根據按一下滑鼠的 localXlocalY 座標,傳回字元的索引。 第一個 if 陳述式會檢查使用者是否已在字元上按一下。 getFirstCharInParagraph() 方法會使用這個索引,傳回同一個段落中第一個字元的索引。 getParagraphLength() 方法所傳回的段落長度會搭配段落中第一個字元的索引使用,以決定段落結束處的索引。 for 迴圈會循環執行段落,尋找 "s" 字元數。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.MouseEvent;

    public class TextField_getParagraphLengthExample extends Sprite {
        private var myTextField:TextField = new TextField();
        private var countField:TextField = new TextField();

        public function TextField_getParagraphLengthExample() {
            myTextField.x = 10;
            myTextField.y = 10;
            myTextField.background = true;
            myTextField.border = true;
            myTextField.wordWrap = true;
            myTextField.width = 300;
            myTextField.height = 280;
            
            myTextField.appendText("The TextField class is used to create display objects for "
                        + "text display and input. All dynamic and input text fields in a SWF file" 
                        + "are instances of the TextField class. You can use the TextField class "
                        + "to perform low-level text rendering. However, in Flex, you typically use "
                        + "the Label, Text, TextArea, and TextInput controls to process text. "  
                        + "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.\n\n"  
                        + "To create a text field dynamically, use the TextField() constructor.\n\n"
                        + "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.");

            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
            
            countField.x = 10;
            countField.y = 300;
            countField.height = 50;
            countField.width = 250;
            countField.background = true;
            countField.selectable = false;

            this.addChild(myTextField);
            this.addChild(countField);
        }

        private function clickHandler(e:MouseEvent):void {
            var index:int = myTextField.getCharIndexAtPoint(e.localX, e.localY);
            
            if(index != -1) {
                var beginParag:int = myTextField.getFirstCharInParagraph(index);
                var paragLength:int = myTextField.getParagraphLength(index);
                var endParag:int = beginParag + paragLength;
                var sCount:uint = 0;

                for (var i:int = beginParag; i <= endParag; i++) {
                    if ((myTextField.text.charAt(i) == "s") || (myTextField.text.charAt(i) == "S")) {
                        sCount++; 
                    }

                countField.text = "Paragraph length is: " + paragLength.toString() + "\n" 
                        + "Number of 's' characters in the paragraph: " + sCount.toString();
                }
            }
        }
    }
}

getTextFormat

()方法 
public function getTextFormat(beginIndex:int = -1, endIndex:int = -1):flash.text:TextFormat

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會傳回 TextFormat 物件,包含 beginIndexendIndex 參數所指定之文字範圍的格式資訊。 唯有對指定之所有文字都通用的屬性,才會在產生的 TextFormat 物件中加以設定。 任何「混合」的屬性,都表示在文字的不同位置會具有不同的值,因此都具有 null 的值。

如果您沒有指定這些參數的值,這個方法便會套用至文字欄位中的所有文字。

下表說明三個可能的用法:

用法說明
my_textField.getTextFormat()傳回 TextFormat 物件,包含文字欄位中所有文字的格式資訊。 只有文字欄位中所有文字通用的屬性才會於產生的 TextFormat 物件中設定。 任何「混合」的屬性,都表示在文字的不同位置會具有不同的值,因此都具有 null 的值。
my_textField.getTextFormat(beginIndex:Number)會傳回 TextFormat 物件,包含在 beginIndex 位置之字元的文字格式副本。
my_textField.getTextFormat(beginIndex:Number,endIndex:Number)傳回 TextFormat 物件,它包含了從 beginIndexendIndex-1 的文字範圍格式資訊。 只有指定範圍裡所有文字通用的屬性才會於產生的 TextFormat 物件中設定。 任何混合的屬性 (在範圍的不同位置具有不同的值) 都會將值設為 null

參數

beginIndex:int (default = -1) — 選擇性整數,指定文字欄位內文字範圍的開始位置。
 
endIndex:int (default = -1) — 選擇性;整數,指定在想要的文字範圍後第一個字元的位置。依原設計,如果您指定 beginIndexendIndex 值,就會讀取從 beginIndexendIndex-1 的文字。

傳回值
flash.text:TextFormat — 代表指定之文字格式屬性的 TextFormat 物件。

擲回值
RangeError — 指定的 beginIndexendIndex 超出範圍。

相關 API 元素


範例
如何使用本範例
如需有關如何使用 getTextFormat() 方法的說明,請參閱 getFirstCharInParagraph()setTextFormat() 方法的範例。

isFontCompatible

()方法 
public static function isFontCompatible(fontName:String, fontStyle:String):Boolean

語言版本: ActionScript 3.0
執行階段版本: Flash Player 10, AIR 1.5, Flash Lite 4

如果指定的 fontNamefontStyle 提供內嵌字體,而 Font.fontTypeflash.text.FontType.EMBEDDED 時,則傳回 true。從 Flash Player 10 開始,可以出現在 SWF 檔中的內嵌字體有兩種:一般內嵌字體只會用於 TextField 物件。CFF 內嵌字體只會用於 flash.text.engine 類別。這兩種類型是由 enumerateFonts() 函數所傳回之 Font 類別的 fontType 屬性所辨別。

TextField 無法使用 EMBEDDED_CFF 類型的字體。如果 embedFonts 是設定為 true,而且在執行階段對於指定的名稱和樣式所能提供的字體屬於類型 EMBEDDED_CFF,Flash Player 便無法顯示文字,就像是未提供指定名稱和樣式的內嵌字體一樣。

如果相同的名稱和樣式提供 EMBEDDEDEMBEDDED_CFF 字體,則會選取 EMBEDDED 字體並使用 EMBEDDED 字體來顯示文字。

參數

fontName:String — 要檢查的內嵌字體名稱。
 
fontStyle:String — 指定要檢查的字體樣式。使用 flash.text.FontStyle

傳回值
Boolean — 如果有相容的內嵌字體可供使用,則為 true,否則為 false

擲回值
ArgumentError — 指定的 fontStyle 不是 flash.text.FontStyle 的成員。

相關 API 元素

replaceSelectedText

()方法 
public function replaceSelectedText(value:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

value 參數的內容取代目前的選取範圍。 文字會插入到目前選取範圍的位置,它會使用目前的預設字元格式和預設段落格式。 並且不會被視為 HTML。

您可以使用 replaceSelectedText() 方法插入並刪除文字,而不中斷文字中其它部分的字元及段落格式。

注意:如果將樣式表套用至文字欄位,這個方法就無法使用。

參數

value:String — 要取代目前選取之文字的字串。


擲回值
Error — 此方法不可用在具有樣式表的文字欄位。

相關 API 元素


範例  ( 如何使用本範例 )

在下列範例中,使用者會選取第一個文字欄位,以清除欄位中的一些文字,然後以 "NEW TEXT" 字串取代第二個文字欄位中選取的文字。

範例建立了兩個不同的 TextField 物件,並為 MouseEvent.MOUSE_UP 事件加入事件偵聽程式。 當使用者放開滑鼠時,會發生「鬆開滑鼠」,這個事件通常發生在選取文字範圍之後。 請注意,文字欄位的預設值是必須選取其文字。

mouseHandler1() 方法中,當使用者在 myTextField1 文字欄位中放開滑鼠時,會清除掉文字,以空白字串取代。 這可以繼續執行,直到所有文字都已清除為止。 在 mouseHandler2() 方法中,當使用者選取 myTextField2 文字欄位中的一些文字時,就會檢查 selectionBeginIndexselectionEndIndex 屬性,確定是否已選取任何字元 (如果已選取一些文字,selectionBeginIndexselectionEndIndex 屬性的值便會不同)。 然後,"NEW TEXT" 字串便會取代選取的文字。 這可以繼續執行,直到第二個文字欄位的所有原始文字都被 "NEW TEXT" 字串取代為止。

package {
    import flash.display.Sprite;
    import flash.text.TextField;    
    import flash.events.MouseEvent;

    public class TextField_replaceSelectedTextExample extends Sprite {
        private var myTextField1:TextField = new TextField();
        private var myTextField2:TextField = new TextField();
        
        public function TextField_replaceSelectedTextExample() {
            myTextField1.x = 10;
            myTextField1.width = 300;
            myTextField1.height = 50; 
            myTextField1.background = true; 
            myTextField1.border = true;
            myTextField1.text = "Select the text you want to remove from the line.";
            
            myTextField2.x = 10;
            myTextField2.y = 60;
            myTextField2.width = 300;
            myTextField2.height = 50;
            myTextField2.background = true;
            myTextField2.border = true;
            myTextField2.text = "Select the text you want to replace with NEW TEXT.";
            
            myTextField1.addEventListener(MouseEvent.MOUSE_UP, mouseHandler1);
            myTextField2.addEventListener(MouseEvent.MOUSE_UP, mouseHandler2);
            
            this.addChild(myTextField1);
            this.addChild(myTextField2);
        }
        
        private function mouseHandler1(e:MouseEvent):void {
            myTextField1.replaceSelectedText("");
        }

        private function mouseHandler2(e:MouseEvent):void {
            if(myTextField2.selectionBeginIndex != myTextField2.selectionEndIndex) {
                myTextField2.replaceSelectedText("NEW TEXT");    
            }
        }
    }
}

replaceText

()方法 
public function replaceText(beginIndex:int, endIndex:int, newText:String):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

beginIndexendIndex 參數所指定的字元範圍,以 newText 參數的內容取代。 依原設計,這會取代從 beginIndexendIndex-1 的文字。

注意:如果將樣式表套用至文字欄位,這個方法就無法使用。

參數

beginIndex:int — 取代範圍之開始位置的索引值 (從零開始)。
 
endIndex:int — 從零開始的索引位置,它是想要的文字範圍後第一個字元的位置。
 
newText:String — 用來取代指定之字元範圍的文字。


擲回值
Error — 此方法不可用在具有樣式表的文字欄位。

範例  ( 如何使用本範例 )

下列範例使用 replaceText() 方法刪除、取代和插入文字欄位中的文字。

outputText 文字欄位會設定為自動符合文字大小,而且以靠左對齊文字的方式調整大小。 第一次呼叫 replaceText() 方法,會將第一行 ("This is the wrong heading") 以 "THIS IS THE HEADING FOR EVERYONE" 取代。 第二次呼叫方法,會將文字 "CORRECT" 插入 "THE" 和 "HEADING" 之間。 第三次呼叫方法,會刪除 "FOR EVERYONE"。 請注意,每一次呼叫 appendText() 方法,目前文字的開始和結束索引都會變更。 這裡只會顯示最終的文字 (進行過各項變更後)。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    
    public class TextField_replaceTextExample extends Sprite {

        public function TextField_replaceTextExample() {
            var outputText:TextField = new TextField();

            outputText.x = 10;
            outputText.y = 10;
            outputText.background = true;
            outputText.autoSize = TextFieldAutoSize.LEFT;
            
            outputText.appendText("This is the wrong heading");
            outputText.appendText("\n\n"); 
            outputText.appendText("This is the body of the text.");

            outputText.replaceText(0, 25, "THIS IS THE HEADING FOR EVERYONE");

            outputText.replaceText(12, 12, "CORRECT ");
            
            outputText.replaceText(27, 40, "");
            
           this.addChild(outputText);
         }
    }
}

setSelection

()方法 
public function setSelection(beginIndex:int, endIndex:int):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會根據第一個和最後一個字元指定的索引值 (以 beginIndexendIndex 參數指定),設定選取文字。 如果這兩個參數值相同,這個方法便會設定插入點,就像是設定 caretIndex 屬性一樣。

參數

beginIndex:int — 選取範圍中第一個字元的索引值 (從零開始,例如,第一個字元是 0,第二個字元是 1,依此類推)。
 
endIndex:int — 選取範圍中最後一個字元的索引值 (從零開始)。

相關 API 元素


範例  ( 如何使用本範例 )

在下列範例中,當使用者按一下文字欄位的任何位置時,會選取預先定義的文字範圍 (反白標示 "TEXT IN ALL CAPS" 幾個字)。

myTextField 文字欄位的兩個事件偵聽程式會回應使用者按一下滑鼠或鬆開滑鼠事件。 當使用者放開滑鼠時,會發生「鬆開滑鼠」,這個事件通常發生在選取文字範圍之後。 請注意,文字欄位的預設值是必須選取其文字。 按一下一些文字時,會叫用 clickHandler() 方法。 選取一些文字並放開滑鼠時,會叫用 mouseUpHandler() 方法。

clickHandler()mouseUpHandler() 等方法中,setSelection() 方法會設定只選取索引 54 和 70 之間的文字 (TEXT IN ALL CAPS)。

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    
    public class TextField_setSelectionExample extends Sprite
    {
        private var myTextField:TextField = new TextField();

        public function TextField_setSelectionExample() {
            myTextField.autoSize = TextFieldAutoSize.LEFT;
            myTextField.text = "No matter where you click on this text field only the TEXT IN ALL CAPS is selected.";

            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);
            myTextField.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

            this.addChild(myTextField);
        }

        private function clickHandler(event:MouseEvent):void {
            myTextField.setSelection(54, 70);
        }

        private function mouseUpHandler(event:MouseEvent):void {
            myTextField.setSelection(54, 70);
        }

    }
}

setTextFormat

()方法 
public function setTextFormat(format:flash.text:TextFormat, beginIndex:int = -1, endIndex:int = -1):void

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會將 format 參數所指定的文字格式套用至文字欄位中的指定文字。 format 的值必須是會指定所需文字格式變更的 TextFormat 物件。 只有 format 的非 null 屬性才會套用至該文字欄位, 設定為 null 的任何 format 屬性則都不會套用。 根據預設,所有新建立的 TextFormat 物件屬性都會設為 null

注意:如果將樣式表套用至文字欄位,這個方法就無法使用。

setTextFormat() 方法會變更套用至字元範圍或文字欄位中,全部文字的文字格式。 若要將格式的屬性套用至文字欄位中的所有文字,請勿指定 beginIndexendIndex 的值。 若要將格式的屬性套用至文字範圍,請指定 beginIndexendIndex 參數值。 您可以使用 length 屬性來判斷索引值。

在 TextFormat 物件中有兩種格式資訊類型,字元等級格式和段落等級格式。 文字欄位中的每個字元都具有其字元格式設定,如字體名稱、字體大小、粗體以及斜體。

對段落而言,段落的第一個字元會當做整段的段落格式設定而進行檢查。 段落格式設定的範例有左方邊界、右方邊界與縮排。

由使用者手動插入、或是由 replaceSelectedText() 方法所取代的任何文字,都會接收新文字的文字欄位預設格式,而非針對文字插入點指定的格式。若要設定新文字的預設格式,請使用 defaultTextFormat

參數

format:flash.text:TextFormat — TextFormat 物件,包含字元和段落格式資訊。
 
beginIndex:int (default = -1) — 選擇性;整數,指定從零開始的索引位置,以指定想要的文字範圍後的第一個字元。
 
endIndex:int (default = -1) — 選擇性;整數,指定想要的文字範圍後的第一個字元。依原設計,如果指定 beginIndexendIndex 值,就會更新從 beginIndexendIndex-1 的文字。

用法說明
my_textField.setTextFormat(textFormat:TextFormat)textFormat 的屬性套用到文字欄位中的所有文字。
my_textField.setTextFormat(textFormat:TextFormat, beginIndex:int)會將 textFormat 的屬性套用到從 beginIndex 位置開始的字元。
my_textField.setTextFormat(textFormat:TextFormat, beginIndex:int, endIndex:int)textFormat 參數的屬性套用到從 beginIndex 位置到 endIndex-1 位置的文字範圍。

請注意,由使用者手動插入、或是由 replaceSelectedText() 方法所取代的任何文字,都會接收新文字的文字欄位預設格式,而非針對文字插入點指定的格式。若要設定新文字之文字欄位的預設格式,請使用 defaultTextFormat 屬性。


擲回值
Error — 此方法不可用在具有樣式表的文字欄位。
 
RangeError — 指定的 beginIndexendIndex 超出範圍。

相關 API 元素


範例  ( 如何使用本範例 )

在下列範例中,按一下文字時,已定義的文字範圍 "TEXT IN ALL CAPS" 會在預設文字格式和新格式之間切換格式。

myTextField 文字欄位的偵聽程式將會加入,以藉由叫用 clickHandler() 方法來回應按一下滑鼠的事件。 在 clickHandler() 方法中,getTextFormat() 方法會傳回所要的文字範圍中字元 (索引 55) 的目前格式,然後將它放入 currentTextFormat TextFormat 物件中。 if 陳述式會檢查 currentTextFormat 文字格式,確認範圍中字元使用的是否為新格式 (字型點數設定為 18 點)。 如果不是,新格式會將大小變更為 18 點、色彩變更為紅色,並對 54-70 之間的文字範圍 (TEXT IN ALL CAPS) 套用底線和斜體。 如果範圍中字元使用的是新格式,則會將範圍的格式設回文字欄位的預設 (原始) 格式。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;  
    import flash.text.TextFieldAutoSize;  
    import flash.events.MouseEvent;

    public class TextField_setTextFormatExample extends Sprite {
        private var myTextField:TextField = new TextField();
        private var newFormat:TextFormat = new TextFormat();
        
        public function TextField_setTextFormatExample() {
            myTextField.autoSize = TextFieldAutoSize.LEFT;
            myTextField.selectable = false;
            myTextField.background = true;
            myTextField.text = "No matter where you click on this text field only the TEXT IN ALL CAPS changes format.";

            myTextField.addEventListener(MouseEvent.CLICK, clickHandler);

            newFormat.color = 0xFF0000;
            newFormat.size = 18;
            newFormat.underline = true;
            newFormat.italic = true;
                
            this.addChild(myTextField);
        }

        private function clickHandler(event:MouseEvent):void {
            var currentTextFormat:TextFormat = myTextField.getTextFormat(55);
            
            if(currentTextFormat.size != 18) {
                myTextField.setTextFormat(newFormat, 54, 70);
            }
            else {
                myTextField.setTextFormat(myTextField.defaultTextFormat);
            }    
        }    
    }
}
事件詳細資訊

change

事件
事件物件類型: flash.events.Event
屬性 Event.type = flash.events.Event.CHANGE

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

在修改控制項值之後傳送,不同於在修改值之前傳送的 textInput 事件。不同於 change 事件的 W3C DOM Event Model 版本,只會在控制項失去焦點後傳送事件,change 事件的 ActionScript 3.0 版本在控制項變更時都會傳送。 例如,如果使用者在文字欄位中輸入文字,change 事件便會在每次按下按鍵之後傳送。

Event.CHANGE 常數會定義 change 事件物件的 type 屬性值。

這個事件具有下列屬性:

屬性
bubblestrue
cancelablefalse;沒有要取消的預設行為指令。
currentTarget正主動使用事件偵聽程式處理 Event 物件的物件。
target其值遭到修改的物件。 target 不會永遠都是顯示清單中註冊事件偵聽程式的物件。 請使用 currentTarget 屬性,存取目前正在處理該事件之顯示清單中的物件。

範例  ( 如何使用本範例 )

在下列範例中,使用者的輸入會立即複製 (反映) 到另一個不同文字格式的文字欄位中。

範例中會建立兩個文字欄位,一個用於使用者輸入,另一個 (headingTextField) 用於複製使用者輸入。 此外,還會建立一個 TextFormat 物件,將預設文字格式指定給 headingTextField 文字欄位。當文字欄位的內容變更時,會叫用 changeHandler() 方法,此方法會將 inputTextField 文字欄位的文字指定給 headingTextField 文字欄位 (如果是為 TextEvent.TEXT_INPUT 事件呼叫這個方法,而不是為 Event.CHANGE 事件呼叫的話,將只會在使用者輸入更多文字後複製使用者輸入的內容)。

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
    import flash.events.Event;
    
    import flash.events.TextEvent;

    public class TextField_Event_changeExample extends Sprite {
        private var inputTextField:TextField = new TextField(); 
        private var headingTextField:TextField = new TextField(); 
        private var newFormat:TextFormat = new TextFormat();
         
        public function TextField_Event_changeExample() {
            headingTextField.x = 10;
            headingTextField.y = 10;
            headingTextField.height = 30;
            headingTextField.width = 400;
            headingTextField.background = true;
            headingTextField.backgroundColor = 0xF5F5DC;
            headingTextField.selectable = false;
 
            inputTextField.x = 10;
            inputTextField.y = 70;
            inputTextField.height = 20;
            inputTextField.width = 230;
            inputTextField.background = true;
            inputTextField.border = true;
            inputTextField.maxChars = 40;
            inputTextField.wordWrap = true;
            inputTextField.type = TextFieldType.INPUT;

            inputTextField.addEventListener(Event.CHANGE, changeHandler);

            newFormat.bold = true;
            newFormat.size = 18;
            newFormat.color = 0xFF0000;
            newFormat.align = TextFormatAlign.CENTER;

            headingTextField.defaultTextFormat = newFormat;

            this.addChild(inputTextField);
            this.addChild(headingTextField);
        }

        private function changeHandler(e:Event):void {
            headingTextField.text = inputTextField.text;
        }
    }
}

link

事件  
事件物件類型: flash.events.TextEvent
屬性 TextEvent.type = flash.events.TextEvent.LINK

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

當使用者按一下已啟用 HTML 功能之文字欄位中的超連結,並且其中的 URL 是以 "event:" 開始時,便會傳送。 URL 在「event:」之後的其餘部分將會放置在 LINK 事件的文字屬性中。

注意: 新增文字至文字欄位的預設行為,只會在 Flash Player 產生此事件時發生。在此情況下,則是在使用者嘗試輸入文字時發生。 將 textInput 事件傳送至文字欄位,並不能將文字放入文字欄位中。

定義 link 事件物件的 type 屬性值。

這個事件具有下列屬性:

屬性
bubblestrue
cancelablefalse;沒有要取消的預設行為指令。
currentTarget正主動使用事件偵聽程式處理 Event 物件的物件。
target包含已經被按一下之超連結的文字欄位。 target 不會永遠都是顯示清單中註冊事件偵聽程式的物件。 請使用 currentTarget 屬性,存取目前正在處理該事件之顯示清單中的物件。
textURL 在 "event:" 之後的其餘部分

範例  ( 如何使用本範例 )

在下列範例中,playMP3() 函數已定義。 建立名為 list 的 TextField 物件,然後在其中填入 HTML 文字。 文字 "Track 1""Track 2" 都是文字欄位中的連結。 當使用者按一下上述任一個連結時,便會呼叫 playMP3() 函數。 MP3 檔案的名稱 (在 HTML 標籤的 href 特質中,此名稱會接在字串 "event:" 後面) 會當做 link 事件物件的 text 屬性傳遞給 linkHandler() 方法。
package {
    import flash.display.Sprite;
    import flash.errors.IOError;
    import flash.events.IOErrorEvent;
    import flash.events.TextEvent;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    public class TextField_event_link extends Sprite
    {
        private var myMP3:Sound;
        public function TextField_event_link() {
            myMP3 = new Sound();
            var list:TextField = new TextField();
            list.autoSize = TextFieldAutoSize.LEFT;
            list.multiline = true;
            list.htmlText = "<a href=\"event:track1.mp3\">Track 1</a><br>";
            list.htmlText += "<a href=\"event:track2.mp3\">Track 2</a><br>";
            addEventListener(TextEvent.LINK, linkHandler);
            addChild(list);
        }
        
        private function playMP3(mp3:String):void {
            try {    
                myMP3.load(new URLRequest(mp3));
                myMP3.play();
            }
            catch(err:Error) {
                trace(err.message);
            }
            myMP3.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
        }
        
        private function linkHandler(linkEvent:TextEvent):void {
            playMP3(linkEvent.text);
        }
        
        private function errorHandler(errorEvent:IOErrorEvent):void {
            trace(errorEvent.text);
        }
    }
}

scroll

事件  
事件物件類型: flash.events.Event
屬性 Event.type = flash.events.Event.SCROLL

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

會在使用者捲動「之後」,由 TextField 物件加以傳送。

Event.SCROLL 常數會定義 scroll 事件物件的 type 屬性值。

這個事件具有下列屬性:

屬性
bubblesfalse
cancelablefalse;沒有要取消的預設行為指令。
currentTarget正主動使用事件偵聽程式處理 Event 物件的物件。
target已經過捲動的 TextField 物件。 這個 target 屬性並非永遠都是註冊事件偵聽之顯示清單中的物件。請使用 currentTarget 屬性,存取目前正在處理該事件之顯示清單中的物件。

範例  ( 如何使用本範例 )

下列範例會定義兩個 TextField 物件。第一個 TextField 物件有兩個關聯的事件處理常式。當您以滑鼠按一下第一個文字欄位內部時,就會傳送 mouseDown 事件,並呼叫關聯的 mouseDownScroll 處理常式。mouseDownScroll() 處理常式會造成此欄位的捲動。然後,會傳送 scroll 事件,而且關聯的 scrollHandler() 處理常式會更新第二個文字欄位,以顯示目前的捲動位置。
package
{
    import flash.display.Sprite;
    import flash.text.*;
    import flash.events.Event;
    import flash.events.TextEvent;
    import flash.events.MouseEvent;

    public class TextScrollExample extends Sprite
    {
        private var myTextBox1:TextField = new TextField();
        private var myTextBox2:TextField = new TextField();
        private var myText:String = "Hello world and welcome to the show. It's really nice to meet you. Take your coat off and stay a while. OK, show is over. Hope you had fun. You can go home now. Don't forget to tip your waiter. There are mints in the bowl by the door. Thank you. Please come again.";

        public function TextScrollExample()
        {
            myTextBox1.text = myText;
            myTextBox1.width = 200;
            myTextBox1.height = 50;
            myTextBox1.multiline = true;
            myTextBox1.wordWrap = true;
            myTextBox1.background = true;
            myTextBox1.border = true;
            
            myTextBox2.x=220;
            myTextBox2.text="scrolled to line: " + myTextBox1.scrollV;

            addChild(myTextBox1);
            addChild(myTextBox2);
            myTextBox1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownScroll);
            myTextBox1.addEventListener(Event.SCROLL, scrollHandler);
        }

        public function mouseDownScroll(event:MouseEvent):void
        {
            myTextBox1.scrollV++;
        }
        public function scrollHandler(event:Event):void
        {
           myTextBox2.text="scrolled to line: " + myTextBox1.scrollV;
        }
    }
}

textInput

事件  
事件物件類型: flash.events.TextEvent
屬性 TextEvent.type = flash.events.TextEvent.TEXT_INPUT

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 9, Flash Lite 4

當使用者輸入一個或多個文字字元時,Flash Player 便會傳送 textInput 事件。 各種不同的文字輸入方法都會產生這個事件,其中包括標準鍵盤、輸入法編輯器 (IME)、語音辨識系統,甚至是貼上純文字 (不含格式或樣式資訊) 的動作。

定義 textInput 事件物件的 type 屬性值。

注意:Delete 或 Backspace 鍵不會傳送這個事件。

這個事件具有下列屬性:

屬性
bubblestrue
cancelabletrue;呼叫 preventDefault() 方法來取消預設行為指令。
currentTarget正主動使用事件偵聽程式處理 Event 物件的物件。
target正在其中輸入字元的文字欄位。 這個 target 並非永遠都是註冊事件偵聽程式之顯示清單中的物件。 請使用 currentTarget 屬性,存取目前正在處理該事件之顯示清單中的物件。
text由使用者所輸入的字元或字元序列。

範例  ( 如何使用本範例 )

下列範例會定義兩個 TextField 物件:第一個 TextField 物件是輸入文字欄位,第二個 TextField 物件是動態文字欄位。當您在第一個文字欄位中輸入文字字元時,將會傳送 textInput 事件、呼叫 textInputHandler() 處理常式,而且字元會顯示在第二個文字欄位中。當您將文字區塊貼入輸入欄位時,事件處理常式會將整個區塊貼入其它欄位。
package
{
    import flash.display.Sprite;
    import flash.text.*;
    import flash.events.Event;
    import flash.events.TextEvent;
    import flash.events.MouseEvent;

    public class TextInputExample extends Sprite
    {
        private var myTextBox1:TextField = new TextField();
        private var myTextBox2:TextField = new TextField();

        public function TextInputExample()
        {
            myTextBox1.type = TextFieldType.INPUT;
            myTextBox1.width = 200;
            myTextBox1.height = 20;
            myTextBox1.background = true;
            myTextBox1.border = true;
            
            myTextBox2.x=220;

            addChild(myTextBox1);
            addChild(myTextBox2);
            myTextBox1.addEventListener(TextEvent.TEXT_INPUT,textInputHandler);
        }

        public function textInputHandler(event:TextEvent):void
        {
           myTextBox2.text=event.text;
        }
    }
}

textInteractionModeChange

事件  
事件物件類型: flash.events.Event

語言版本: ActionScript 3.0
執行階段版本: AIR 1.0, Flash Player 11, Flash Lite 4

當使用者變更文字欄位的互動模式時,Flash Player 會傳送 textInteractionModeChange 事件。例如,在 Android 可以使用快顯選單選項將 NORMAL 模式切換為 SELECTION 模式。

TextFieldExample.as

下列範例將使用 TextFieldExample 類別來顯示一段文字訊息。 這是使用下列步驟達成的:
  1. 建立類型為 TextField 的 label 屬性。
  2. 類別建構函式會呼叫 configureLabel() 函數。
  3. configureLabel() 方法會先建立新的 TextField 物件並將它指定給 label 屬性,然後將它的參數設定為下列各項:
    • 使文字欄位左側對齊。
    • 啟用背景填色。
    • 啟用邊框。
  4. configureLabel() 方法會建立 format 變數,將它的參數設定為下列各項後再指定給新的 TextFormat 實體:
    • Font type = Verdana
    • Font color = solid red
    • Font size = 10
    • Font underline = true
  5. label 文字欄位的 defaultTextFormat 屬性已經設定為 formatlabel 實體也已經加入顯示清單,舞台上就會開始顯示一個不含文字的文字欄位。
  6. 該建構函式會將 label 文字欄位的文字設定為 "Hello world and welcome to the show."。,方式是呼叫 setLabel() 方法。
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;


    public class TextFieldExample extends Sprite {
        private var label:TextField;
        private var labelText:String = "Hello world and welcome to the show.";

        public function TextFieldExample() {
            configureLabel();
            setLabel(labelText);
        }

        public function setLabel(str:String):void {
            label.text = str;
        }

        private function configureLabel():void {
            label = new TextField();
            label.autoSize = TextFieldAutoSize.LEFT;
            label.background = true;
            label.border = true;

            var format:TextFormat = new TextFormat();
            format.font = "Verdana";
            format.color = 0xFF0000;
            format.size = 10;
            format.underline = true;

            label.defaultTextFormat = format;
            addChild(label);
        }
    }
}




[ X ]為什麼顯示英文?
「ActionScript 3.0 參考」的內容是以英文顯示

並非所有「ActionScript 3.0 參考」的內容都翻譯為所有語言。當語言元素未翻譯時,就會以英文顯示。例如,ga.controls.HelpBox 類別並沒有翻譯為任何語言。因此在參考的繁體中文版本中,ga.controls.HelpBox 類別就會以英文顯示。