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

Home
Flash / Flex / ActionScript
1.Animation
2.Array
3.Class
4.Data Type
5.Development
6.Function
7.Graphics
8.Language
9.Network
10.Regular Expressions
11.Statement
12.String
13.TextField
14.XML
Flash / Flex / ActionScript » Development » Focus Event 
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.