1 Reply Latest reply on Jan 16, 2008 8:59 AM by theklue

    Event handler behavior

    apo11o1
      Simple question:
      Note the line in the handler which is commented... if this remains commented, the text box is not cleared when I press the 'A' key. However, if I allow that alert to occur, the textbox is cleared. This does not make sense to me... what don't I understand here?

      Thanks




      DeleteTextArea.as
      quote:

      package components
      {
      import mx.controls.TextArea;
      import flash.events.KeyboardEvent;
      import mx.controls.Alert;

      public class DeleteTextArea extends TextArea {
      public function DeleteTextArea() {
      super();
      addEventListener("keyDown", myKeyDown);
      }

      private function myKeyDown(eventObj:KeyboardEvent):void {
      if (eventObj.keyCode == 65) { // 'A' key
      text = "";
      //Alert.show('Alert'); // if uncommented, text area is cleared, else not cleared
      }
      }
      }
      }


      Test.mxml
      quote:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:cp="components.*" layout="absolute">
      <cp:DeleteTextArea/>
      </mx:Application>