Skip to main content
April 22, 2009
Question

Restrict chars property

  • April 22, 2009
  • 1 reply
  • 744 views

Hi,

Sorry if this has been covered already, but is there a property I can set to restrict characters entered in an editable container? Or do I have to listen to the FlowOperationEvent and remove any chars I don't like after they've been typed ... or is there another way.

thanks.

This topic has been closed for replies.

1 reply

Adobe Employee
April 22, 2009

There is no restrict chars property in TLF, but there is in the Flex Gumbo components that use TLF. You may want to look at using the Gumbo components. If that doesn't work for you, and you want to do it yourself, the best way is to listen for the FlowOperationEnd event, which gets sent after the operation has fired. Check the textLength of the textflow there, and if it's over your limit, call back into the EditManager to delete the extra characters. It will all undo a single unit.

Here's a sketch at how this might look:

         textFlow.addEventListener(FlowOperationEvent.FLOW_OPERATION_END,limitPaste,false,0,true);

          private function limitPaste(event:FlowOperationEvent):void

              {
                   if (textFlow.textLength > maxFlowLength)
                  {
                      var trimAmt:int = textFlow.textLength - maxFlowLength;
                      var pasteEnd:int = pastePosition + (operation.absoluteEnd - operation.absoluteStart);
                      textFlow.interactionManager.setSelection(pasteEnd - trimAmt, pasteEnd);
                      ( textFlow.interactionManager as IEditManager).deleteNext();
                  }
              }

This is not fully debugged code, but it should give you an idea how to go ahead -- or you can use Gumbo.