Listening to TextField Events : text event « TextField « Flash / Flex / ActionScript






Listening to TextField Events

 
textInput Event

package
{
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.events.TextEvent;
    public class Main extends Sprite
    {
        private var inputText:TextField;
        private var regex:RegExp;
        private var dict:Array;

        public function Main()
        {

            dict = new Array("flash", "java", "C#", "python", "ruby", "C++");
            inputText = new TextField();
            inputText.type = "input";
            inputText.addEventListener(TextEvent.TEXT_INPUT, predictText);
            inputText.border = true;
            addChild(inputText);
        }

        private function predictText(textEvent:TextEvent):void
        {
            this.regex = new RegExp(textEvent.text, "i");
            for each(var term:String in dict)

            {
                if(regex.test(term))
                {
                    inputText.text = term.substring(textEvent.text.length);
                }
            }
        }
    }
}

        








Related examples in the same category

1.Responding to User Text Entry: field.addEventListener(TextEvent.TEXT_INPUT, onTextInput);
2.Calling ActionScript from Hyperlinks
3.Prevent Default Test