FocusEvent.MOUSE_FOCUS_CHANGE : Focus Event « Development « Flash / Flex / ActionScript






FocusEvent.MOUSE_FOCUS_CHANGE

 

package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.FocusEvent;

    public class Main extends Sprite
    {
        public function Main()
        {
            var tf1:TextField = new TextField();
            tf1.type = "input";
            tf1.height = 20;
            tf1.width = 100;
            tf1.border = true;

            addChild(tf1);
            tf1.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, checkFocus);

            var tf2:TextField = new TextField();
            tf2.type = "input";
            tf2.height = 20;
            tf2.width = 100;
            tf2.border = true;
            addChild(tf2);
            tf2.x = 200;
        }

        private function checkFocus(focusEvent:FocusEvent):void
        {
            if ((focusEvent.target as TextField).text == "")
            {
                focusEvent.preventDefault();
            }
        }
    }
}

        








Related examples in the same category

1.FocusEvent.KEY_FOCUS_CHANGE
2.Handling focus events globally
3.Handling focus events for a particular object
4.Focus and Tab Events
5.focusIn and focusOut Events