vendredi 29 mai 2015

Get textinput number of character in Flex

I have textinput in flex we application.

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

Where i limit maxChars to 2. It works when i remove editable="false" from textinput and type using keyboard.

Problem:
But same thing is not works when i do using button click like:

<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)"/>

On click of button insertlabel value in textinput like:

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

The above thing is not working. It will insert more than 2 character in textInput.

Any one help me to figure-out this issue?
How can i restrict max 2 character in textinput?

Aucun commentaire:

Enregistrer un commentaire