Listening to TextField Events : Text event : TextField Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » TextField » Text event »

 

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);
                }
            }
        }
    }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo TextField
» Text event