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


Flash / Flex / ActionScript examples » Development » Focus Event »

 

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(0x00ff001);
            spr.graphics.drawRect(00100100);
            spr.graphics.endFill();
            sprTwo.graphics.beginFill(0x0000ff1);
            sprTwo.graphics.drawRect(00100100);
            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);
        }
    }
}

        



Leave a Comment / Note


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


Flash / Flex / ActionScript examples

 Navioo Development
» Focus Event