Prevent Default Test : text event « TextField « Flash / Flex / ActionScript






Prevent Default Test

 
package {
     
     import flash.display.Sprite;
     import flash.text.TextField;
     import flash.text.TextFieldType;
     import flash.events.TextEvent;
     
     [SWF(width=550, height=400)]

     public class Main extends Sprite {
     
          public function Main() {
               var tf:TextField = new TextField();
               addChild(tf);
               
               tf.width = stage.stageWidth;
               tf.height = stage.stageWidth;
               tf.type = TextFieldType.INPUT;
               tf.wordWrap = true;
               
               tf.addEventListener(TextEvent.TEXT_INPUT, onTextFieldTextInput);
          }
          
          private function onTextFieldTextInput(event:TextEvent):void {
               var tf:TextField = event.target as TextField;
               if (tf.text.indexOf(event.text) > -1) {
                    event.preventDefault();
               }
          }
     
     }

}

        








Related examples in the same category

1.Responding to User Text Entry: field.addEventListener(TextEvent.TEXT_INPUT, onTextInput);
2.Calling ActionScript from Hyperlinks
3.Listening to TextField Events