Hi,
 
None of the Flex components handle double-click mouse events at the moment. Well you have obviously created an alternative or you can call the following piece of code on thecellPress event of a DataGrid for example to detect and handle a double-click:
 
/*
 Handles the double-click event on the inbox display grid.
 */
 public function cellPressEvt( evt:Object ):Void {
  var now = new Date();
 
  // we got a double-click
  if( ( now.getTime() - timestamp.getTime() ) < 375 && view.inboxGrid.selectedItem != undefined ) {
   // do something..
  }
  
  timestamp = new Date();
 }
 
Jimmy Gianninas
Software Developer - Optimal Payments Inc.
 


From: stealthbaz [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 01, 2005 9:55 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders]Double Clicking -- A Question... and my Answer, the Double Click component.


So as i'm making my first app in Flex, I keep coming across questions.

My first question is:  Is there a built in event handler for
doubleClick detection?

Please respond and let me know if I missed something.

In the meantime after poking around, I could not find one.  So I built
one.  :)

My component has 2 major pieces of functionality.  First it contains
an AS function that can detect a double click.  But since I'm sick in
the head, I didn't stop there.  I added an interface to alter the
speed of the double click, as well as test it.


Below is my component for detecting double click.  If you want to use
it in your app, you simply include it inyour app as a component with
no height, width, or visibility. A method in your app can make it
visible for when the user wants to change the settings of the mouse
speed.    I used the shared object to retain the mouse speed settings.

The inclusion line in your App:
-------  CODE  ---------------

<DoubleClick id="doubleClick" visible="false" height="0" width="0"/>

--------  END CODE------------------


Once its in included, you can just reference it in your mouseDown
handlers:

The line to actually detect a double click. (using some imaginary
button in your app)
-----   CODE  ------------------

<mx:Button label="Double Click Me" mouseDown="if
(doubleClick.detectDoubleClick()){mx.controls.Alert.show('Double Click
Detected', '');}"/>           

----   END CODE------------------




And lastly, the component itself.
You can alter it, muck with it, or do whatever you want to it.
Critique, pointers, etc.. are all welcome.


----  CODE -----------

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Canvas xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Panel label="Double Click Speed" initialize="l
oadDoubleClickSpeed()">
<mx:Script>
<![CDATA[
/*
---- This component is free to use, alter, distribute, or ignore ----
As I was starting to learn flex, and work on my own first App, I could
not find away to perform
a double click event handle. 


Russell Miner
[EMAIL PROTECTED]

*/

var global_mouseTimer = 0; //The variable to keep track of the last
mouse click time
var doubleClickTime = 300; // The variable to provide the minimum time
needed to elapse for a double click to count

/*
This method will return true if a double click was detected and false
if not.
It should be called as the eventhandler of a mouseDown event.  

Eg:    mouseDown="if
(detectDoubleClick()){mx.controls.Alert.show('Double Click Detected',
'');}"

*/
function detectDoubleClick(){
      var aDate = new Date();
      var now = aDate.getTime();                 
      if (now -global_mouseTimer < doubleClickTime){
           global_mouseTimer = now;           
            return true;
      }else{
            //too slow
           global_mouseTimer = now;
            return false;                 
      }     
}

/*
This method will reload the last setting of the mouse speed
*/
function loadDoubleClickSpeed(){
      var so:SharedObject = SharedObject.getLocal("_doubleClickTime");     
      doubleClickTime = so.data.doubleClickTime;
}

/*
The handler for the changing of the click speed slider
*/
function handleDoubleClickSpeedChange(event){
      doubleClickTime = doubleClickSlider.value;
      var so:SharedObject = SharedObject.getLocal("_doubleClickTime");
      so.data.doubleClickTime = doubleClickTime;
      so.flush();           
}


/*
These are left to be implemented by the user.  They can make this
component show or hide based on your particular implementation
*/
function showMe(){
}
function hideMe(){
     
}
]]>



</mx:Script>
    <mx:VBox horizontalAlign="center" verticalGap="20">
         <mx:Text text="Choose a double click speed in milliseconds, then
test on the button below" width="170" height="48" />
            <mx:HSlider id="doubleClickSlider"
                              change="handleDoubleClickSpeedChange(event)"
                              minimum="0"
                              maximum="1000"
                              liveDragging="true"
                              tickInterval="100"
                              value="{doubleClickTime}"
                              labels="['0', '1000']"
                              width="75%"/>
            <mx:Button label="Double Click Me" mouseDown="if
(detectDoubleClick()){mx.controls.Alert.show('Double Click
Detected', '');}"/>           
      </mx:VBox>
</mx:Panel>
</mx:Canvas>
</mx:Application>


----  END CODE ------






AVIS IMPORTANTWARNING

Les informations contenues dans le present document etses pieces jointes sont strictement confidentielles et reservees a l'usagede la (des) personne(s) a qui il est adresse. Si vous n'etes pas le destinataire, soyez avise que toute divulgation, distribution, copie, ou autre utilisation de ces informations est strictement prohibee. Si vous avez recu ce document par erreur, veuillez s'il vous plait communiquer immediatement avec l'expediteur et detruire ce document sans en faire de copie sous quelque forme.

The information contained in this document and attachments is confidential and intended only for the person(s) named above. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution, or any other use of the information isstrictly prohibited. If you have received this document by mistake, pleasenotify the sender immediately and destroy this document and attachments without making any copy of any kind.


Reply via email to