Focus and Tab Events : Focus Event « Development « Flash / Flex / ActionScript






Focus and Tab Events

 
package{
  import flash.display.*;
  import flash.events.*;
  public class Main extends Sprite
  {
        public function Main()
        {
            var spr:Sprite = new Sprite();
            var sprTwo:Sprite = new Sprite();
            spr.graphics.beginFill(0x00ff00, 1);
            spr.graphics.drawRect(0, 0, 100, 100);
            spr.graphics.endFill();
            sprTwo.graphics.beginFill(0x0000ff, 1);
            sprTwo.graphics.drawRect(0, 0, 100, 100);
            sprTwo.graphics.endFill();

            var btnOne:SimpleButton = new SimpleButton(spr, spr, spr, spr);
            var btnTwo:SimpleButton = new SimpleButton(sprTwo, sprTwo, sprTwo, sprTwo);

            addChild(btnOne);
            addChild(btnTwo);

            sprTwo.x = 300;

            btnOne.addEventListener(MouseEvent.MOUSE_OVER, focusMe);
            btnTwo.addEventListener(MouseEvent.MOUSE_OVER, focusMe);

            btnOne.addEventListener(FocusEvent.FOCUS_IN, fin);
            btnOne.addEventListener(FocusEvent.FOCUS_OUT, fout);
            btnTwo.addEventListener(FocusEvent.FOCUS_IN, fin);
            btnTwo.addEventListener(FocusEvent.FOCUS_OUT, fout);

        }

        private function fin(focusEvent:FocusEvent):void
        {

            trace(' focus in '+focusEvent.target+' related object '+focusEvent.relatedObject);
        }

        private function fout(focusEvent:FocusEvent):void
        {
            trace(' focus out '+focusEvent.target+' related object'+focusEvent.relatedObject);
        }

        private function focusMe(mouseEvent:MouseEvent):void
        {
            trace("stage focus ");
            stage.focus = (mouseEvent.target as InteractiveObject);
        }
    }
}

        








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.focusIn and focusOut Events
5.FocusEvent.MOUSE_FOCUS_CHANGE