[英]How to campture the text change event of a text control to call a function in Flex 3
我是flex的新手,無法捕獲文本控件的文本更改事件:
<mx:Text id="description"
text=""
textAlign="center"
fontSize="18"
click="_playSpeech()" />
現在是單擊,但是我需要像textChange =“ _ playSpeech()”這樣的東西,因此每次控件的文本更改時,它都會調用該函數。
非常感謝您的幫助。
在代碼中執行此操作的一種簡單方法是將文本更新包裝到函數中:
protected function updateDescription(text:String):void
{
description.text=text;
_playSearch();
}
然后始終調用函數,而不是立即更改文本字段。 還可以防止不必要地使用事件。
如果您正在觀看用戶在文本框本身中輸入的更改,則應使用TextArea或TextInput類代替Text 。 這使您可以聽這樣的更改:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
protected function onTextChangeHandler(event:Event):void
{
trace("text has changed")
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:TextArea id="description"
text="text to change goes here ..."
textAlign="center"
fontSize="18"
change="onTextChangeHandler(event)" />
</s:Application>
如果要在文本框外更改文本,我建議您制作一個可綁定的變量或觸發您要執行的操作的函數。
您將需要像這樣注冊更改事件(注意,我使用的是TextInput而不是Text):
<mx:TextInput id="description" text="" fontSize="18" change="_playSpeach()"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.