7 Replies Latest reply on Jul 30, 2007 7:48 AM by Newsgroup_User

    DOUBLE_CLICK help

    theyinhe
      I can't understand why this code doesn't work, please help.


      button1.addEventListener (MouseEvent.DOUBLE_CLICK, clickHandler);
      function clickHandler(event:MouseEvent):void {
      var url:String = " http://www.hotmail.com";
      var request:URLRequest = new URLRequest(url);
      try {
      navigateToURL(request);
      } catch (e:Error) {
      trace("Error occurred!");
      }
      }

      However, CLICK works fine.

      Thanks,

      Yin
        • 1. Re: DOUBLE_CLICK help
          Level 7
          theyinhe,

          > I can't understand why this code doesn't work, please help.
          >
          >
          > button1.addEventListener (MouseEvent.DOUBLE_CLICK, clickHandler);
          // snipped code

          > However, CLICK works fine.

          Did you set the button's doubleClickEnabled property to true?


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: DOUBLE_CLICK help
            kglad Adobe Community Professional & MVP
            use button1.doubleClickEnabled=true;
            • 3. Re: DOUBLE_CLICK help
              theyinhe Level 1
              Thanks so much for your help! Are there any good resources for Actionscript 3? Unfortunately, none of the books on the subject are going to be out until a few months from now...
              • 4. Re: DOUBLE_CLICK help
                kglad Adobe Community Professional & MVP
                www.senocular.com has lots of helpful information.
                • 5. Re: DOUBLE_CLICK help
                  Level 7
                  Hi everyone,

                  According to the documentation on this function:

                  "If the target InteractiveObject does not have its doubleClickEnabled
                  flag set to true it receives two click events."

                  The code I have is:

                  public function onDoubleCick(eventObj:MouseEvent):void {
                  trace ('double click!');
                  }

                  //in constructort
                  this.addEventListener(MouseEvent.DOUBLE_CLICK,this.onDoubleClick);

                  Setting the doubleClickEnabled flag works fine, but when it's set to
                  false, this same code simply doesn't work. It doesn't fire the function
                  off twice in quick succession or anything, it simply does nothing. Does
                  anyone know why?

                  Thanks,
                  Partick



                  kglad wrote:
                  > www.senocular.com has lots of helpful information.

                  --
                  http://www.baynewmedia.com
                  Faster, easier, better...ActionScript development taken to new heights.
                  Download the BNMAPI today. You'll wonder how you ever did without it!
                  Available for ActionScript 2.0/3.0.
                  • 6. Re: DOUBLE_CLICK help
                    Level 7
                    Patrick,

                    > Setting the doubleClickEnabled flag works fine, but
                    > when it's set to false, this same code simply doesn't work.
                    > It doesn't fire the function off twice in quick succession or
                    > anything, it simply does nothing. Does anyone know why?

                    The only explanation I would venture is that the event handler is
                    specifically listening for the MouseEvent.DOUBLE_CLICK event. By
                    definition, that isn't a succession of single clicks, it's a double click.

                    If you write an event handler for MouseEvent.CLICK, you'll see it fire
                    for single clicks, but not double clicks, which may clarify the distinction
                    (admittedly a subtle one). For example, this snippet:

                    btn.doubleClickEnabled = true;
                    btn.addEventListener(
                    MouseEvent.CLICK,
                    function(e:MouseEvent):void {
                    trace("single click")
                    }
                    );
                    btn.addEventListener(
                    MouseEvent.DOUBLE_CLICK,
                    function(e:MouseEvent):void {
                    trace("double click")
                    }
                    );

                    ... outputs the following in a double-click situation:

                    single click
                    double click


                    David Stiller
                    Adobe Community Expert
                    Dev blog, http://www.quip.net/blog/
                    "Luck is the residue of good design."


                    • 7. Re: DOUBLE_CLICK help
                      Level 7
                      Woops. I mean to add:

                      And if you comment out the line btn.doubleClickEnabled = true; (or
                      change it to false), the CLICK event handler outputs its line twice in
                      response to a quick succession of clicks.


                      David Stiller
                      Adobe Community Expert
                      Dev blog, http://www.quip.net/blog/
                      "Luck is the residue of good design."