0 Replies Latest reply on May 18, 2008 9:06 PM by brmcc

    How to doubleClick-enable a TextField?

      The code below works, but after setting stage.focus in the doubleClick handler the TextField is in some sort of drag state as can be seen by moving the mouse left and right after the double click (after the mouse button is released). Any advice anyone? Alternate approaches?

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

      import flash.text.*;

      public function initApp():void

      private function createTextField(x:int, y:int, s:String) : TextField
      var tf:TextField = new TextField();
      tf.type = TextFieldType.INPUT;
      tf.width = 80;
      tf.height = 40;
      tf.border = true;
      tf.text = s;
      tf.x = x;
      tf.y = y;
      tf.doubleClickEnabled = true;
      this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
      tf.addEventListener(MouseEvent.DOUBLE_CLICK, mouseDouble);
      return tf;

      private function mouseDown(event:MouseEvent):void
      // take away the focus on a single click -- there may be a
      // better way to do this but it seems to work.
      stage.focus = null; // undo focus
      private function mouseDouble(event:MouseEvent):void
      var tf:TextField = event.target as TextField;
      stage.focus = tf; // works, but tf is in some sort of drag state

      <mx:UIComponent id="canvas" width="200" height="100"/>