Responding When Text Is Selected or Deselected : Focus event : TextField Flash / Flex / ActionScript examples


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

 

Responding When Text Is Selected or Deselected


 

package {

  import flash.display.Sprite;
  import flash.text.TextField;
  import flash.text.TextFieldType;
  import flash.events.FocusEvent;
  
  public class Main extends Sprite {

    private var _field1:TextField = new TextField(  );
    private var _field2:TextField = new TextField(  );

    public function Main(  ) {
      _field1.border = true;
      _field1.background = true;
      _field1.type = TextFieldType.INPUT;
      addChild(_field1);
      _field1.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, onKeyFocus);
      _field2.border = true;
      _field2.background = true;
      _field2.type = TextFieldType.INPUT;
      addChild(_field2);
      _field2.y = 100;
      
    }
    
    private function onKeyFocus(event:FocusEvent):void {
      if(_field1.text == "") {
          event.preventDefault(  );
      }
    }
  }
}

        



Leave a Comment / Note


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


Flash / Flex / ActionScript examples

 Navioo TextField
» Focus event