获取Flex中textinput的字符数

时间:2015-05-29 10:09:16

标签: actionscript-3 flex actionscript flex4.6

我在flex应用中有textinput。

<s:TextInput id="txtGuestCount" maxChars="2" editable="false"/>

我将maxChars限制为2.当我从textinput中删除editable="false"并使用键盘输入时,它可以正常工作。

问题:
但是当我使用按钮点击时,同样的事情是行不通的:

<s:Button width="50" height="50"  chromeColor="#ffffff" label="1" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="2" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="3" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="4" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="5" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="6" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="7" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="8" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="9" buttonMode="true" click="onNumberClick(event)"/>
<s:Button width="50" height="50"  chromeColor="#ffffff" label="0" buttonMode="true" click="onNumberClick(event)"/>

点击textinput中的按钮insertlabel值,如:

protected function onNumberClick(event:MouseEvent):void
{
   txtGuestCount.text += event.currentTarget.label;
}

上面的东西不起作用。它将在textInput中插入2个以上的字符。

任何人帮我解决这个问题?
如何限制textinput中的最大2个字符?

1 个答案:

答案 0 :(得分:2)

根据manual,在代码中更改 var values = new Dictionary<string, string> { {"ctl00$txtSearchProduct", ""}, {"ctl00$TextArea", ""}, {"ctl00$MainContent$chain", "7290058179503"}, //company id {"ctl00$MainContent$subChain", "-1"}, {"ctl00$MainContent$branch", "-1"}, {"ctl00$MainContent$txtDate", ""}, {"ctl00$MainContent$fileType", "all"}, {"__EVENTTARGET", fileParam}, {"__EVENTARGUMENT", ""}, {"__LASTFOCUS", ""}, {"__VIEWSTATE", viewState}, }; //exception here var content2 = new FormUrlEncodedContent(values); var response = await client.PostAsync(BaseUrl, content2); 时,不会检查maxChars。因此,您必须手动控制text的新值不超过2个字符。一个例子:

text