The textinput component has the maxchars attribute to limit the number of input texts, but does not support halfwidth and fullwidth. I checked the information online and finally got some results. The following example is provided for your reference:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <s: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" <br/> xmlns: S = "Library: // ns.adobe.com/flex/spark" <br/> xmlns: MX = "Library: // ns.adobe.com/flex/mx" <br/> minwidth = "955" minheight = "600"> <br/> <FX: SCRIPT> <br/> <! -- [CDATA [<br/> Import flash. desktop. clipboard; <br/> Import flash. desktop. clipboardformats; </P> <p> Import flashx. textlayout. edit. selectionstate; <br/> Import flashx. textlayout. operations. inserttextoperation; <br/> Import flashx. textlayout. operations. pasteoperation; </P> <p> Import spark. events. textoperationevent; <br/>/** <br/> * changinghandler <br/> * text input ing, full-width half-width text count verification <br/> * @ Param textoperat Ionevent event <br/> * @ return void <br/> ***/<br/> protected function changinghandler (Event: textoperationevent ): void <br/>{< br/> var target: textinput = event. currenttarget as textinput; </P> <p> If (target. maxchars <= 0) return; </P> <p> // original text <br/> var oldtext: String = target. text; </P> <p> // newly appended text <br/> var addtext: string; </P> <p> // The length of the selected text (the text to be overwritten) <br/> var dellen: int; </P> <p> // total text length <br/> var totallen: I NT; </P> <p> var insertop: inserttextoperation; <br/> var pasteop: pasteoperation; </P> <p> var selectstate: selectionstate; </P> <p> If (event. operation is inserttextoperation) {<br/> // text insertion <br/> insertop = event. operation as inserttextoperation; </P> <p> // obtain the newly appended text. <br/> addtext = insertop. text; </P> <p> // obtain the object of the selected text <br/> selectstate = insertop. deleteselectionstate; </P> <p> dellen = selectstate? Getbytelenbystr (oldtext. substring (selectstate. absolutestart, selectstate. absoluteend): 0; </P> <p> // total length <br/> totallen = getbytelenbystr (oldtext) + getbytelenbystr (addtext)-dellen; </P> <p> If (totallen> target. maxchars) event. preventdefault (); </P> <p>} else if (event. operation is pasteoperation) {<br/> // text paste <br/> pasteop = event. operation as pasteoperation; </P> <p> // obtain the pasted text <br/> addtext = clipboar D. generalclipboard. getdata (clipboardformats. text_format) as string; </P> <p> // obtain the object of the selected text <br/> selectstate = pasteop. originalselectionstate; </P> <p> dellen = selectstate? Getbytelenbystr (oldtext. substring (selectstate. absolutestart, selectstate. absoluteend): 0; </P> <p> // total length <br/> totallen = getbytelenbystr (oldtext) + getbytelenbystr (addtext)-dellen; </P> <p> If (totallen> target. maxchars) event. preventdefault (); </P> <p >}// if event. operation End </P> <p >}</P> <p>/** <br/> * getbytelenbystr <br/> * Get the length of string bytes (1 byte) 2 bytes) <br/> * @ Param string Val <br/> * @ Param String charset <br/> * @ return uint <br/> ***/<br/> Public Function getbytelenbystr (VAL: String, charset: String = "utf8 "): uint <br/>{< br/> If (! Val) return 0; </P> <p> var bytearr: bytearray = new bytearray (); </P> <p> bytearr. writemultibyte (Val, charset); <br/> bytearr. position = 0; </P> <p> return bytearr. length; <br/>}</P> <p>] --> <br/> </FX: SCRIPT> </P> <p> <FX: declarations> </P> <p> </FX: declarations> </P> <p> <s: layout> <br/> <s: verticallayout paddingtop = "10" paddingleft = "10"/> <br/> </S: layout> </P> <p> <s: label text = "maxchars for text input halfwidth and fullwidth"/> </P> <p> <s: hgroup verticalalign = "bottom"> <br/> <s: textinput changing = "changinghandler (Event) "width =" 100 "maxchars =" 10 "/> <br/> <s: label text = "10 characters in width and 5 Characters in width"/> <br/> </S: hgroup> </P> <p> </s: application> <br/>