2 Replies Latest reply on Mar 4, 2007 1:16 PM by pleska

    DoubleClick and Click question

    pleska
      I cannot see to find if this is just a limitation of the current flex and actionscript but is there a way to receive both a click and doubleclick on a canvas.

      Say I have a canvas like

      <mx:Canvas id="test1" x="35" y="1" width="16" height="16" backgroundColor="#ffffff" doubleClickEnabled="true" borderStyle="solid" borderThickness="1" borderColor="#ffffff">
      </mx:Canvas>

      that has doubleClickEnabled set to true

      and I have code later that

      test1.addEventListener(MouseEvent.DOUBLE_CLICK, onTestDoubleClick );
      test1.addEventListener(MouseEvent.CLICK, onTestClick );

      I get one or the other event firing depending on which event listener I comment out.

      I really would like the system to send a click event if another doesn't arrive in some system defined double click threshold of time otherwise send the doubleclick.

      Am I doing something wrong?

      And if you just can't do this has anyone used some timer or thread solution on the single click handler to dispatch a double click based on time or let the original single click get sent?

      Thanks,

      :) Paul

        • 1. Re: DoubleClick and Click question
          jonrmayer
          HI - This is no answer but I am having exactly the same problems:-

          Here's some fuller code:-

          import flash.events.MouseEvent;
          import mx.controls.Alert;
          private function initApp():void{



          this.addEventListener(MouseEvent.MOUSE_WHEEL,mw,false,2);
          this.addEventListener(MouseEvent.DOUBLE_CLICK,dc,false,3);

          this.addEventListener(MouseEvent.CLICK,lc,false,1)



          }

          private function lc(evt:MouseEvent):void{

          var x:Number = Number(evt.localX);
          var y:Number = Number(evt.localY);

          Alert.show("Center @ " + " " + x.toString() + " " + y.toString());






          }

          private function dc(evt:MouseEvent):void{

          var x:Number = Number(evt.localX);
          var y:Number = Number(evt.localY);

          Alert.show("Zoom In & Center @ " + " " + x.toString() + " " + y.toString());






          }

          private function mw(evt:MouseEvent):void{
          var i:Number = Number(evt.delta);
          var x:Number = Number(evt.localX);
          var y:Number = Number(evt.localY);
          if(i>0){
          Alert.show("FWD" + " " + x.toString() + " " + y.toString());
          }
          if(i<0){
          Alert.show("BWD" + " " + x.toString() + " " + y.toString());
          }


          }



          Best

          Jonathan
          • 2. Re: DoubleClick and Click question
            pleska Level 1
            I got it working but my click event was reversable. During a click I was toggling something to show or hide and on double click I was selecting it. I accomplished both on a canvas by doing the following.

            <mx:Canvas id="entry1" x="1" y="1" width="16" height="16"
            backgroundColor="#ffffff" borderStyle="solid" borderThickness="1" borderColor="#ffffff">
            <mx:Text id="entry1text" text="1" width="16" height="16"
            fontFamily="Verdana" textAlign="center" fontSize="12"
            fontWeight="bold" selectable="false" verticalCenter="-2">
            </mx:Text>
            </mx:Canvas>

            <mx:Script>
            <![CDATA[
            private var _lastClickTime:Number = 0;

            public function init():void
            {
            entry1.addEventListener(MouseEvent.CLICK, onEntry1Click );
            }


            public function isDoubleClick(): Boolean
            {
            var nowDate:Date = new Date();
            var nowMS:Number = nowDate.getTime();
            if ( ( (nowMS - _lastClickTime ) < 350 ) )
            {
            _lastClickTime = 0;
            return true;
            }
            trackClick();
            return false;
            }

            public function trackClick() : void
            {
            var nowDate:Date = new Date();
            var nowMS:Number = nowDate.getTime();
            _lastClickTime = nowMS;
            }

            public function onEntry1Click( e:MouseEvent ): void
            {
            if ( isDoubleClick(t) )
            {
            Reverse the first click
            Process the Double Click
            }
            else
            {
            Process the Click
            }
            }
            ]]>
            </mx:Script>