Responding to User Text Entry: field.addEventListener(TextEvent.TEXT_INPUT, onTextInput);
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.events.TextEvent;
import flash.events.TextEvent;
public class Main extends Sprite {
private var _field:TextField = new TextField( );
public function Main( ) {
_field.border = true;
_field.background = true;
_field.type = TextFieldType.INPUT;
addChild(_field);
_field.addEventListener(TextEvent.TEXT_INPUT, onTextInput);
}
private function onTextInput(event:TextEvent):void {
if(event.text == "a" && _field.length == 0) {
event.preventDefault( );
}
}
}
}
Related examples in the same category