http://raghuonflex.wordpress.com/2007/08/10/assigning-different-behaviors-on-click-doubleclick/
This interesting issue was posted by Arpan on the flex_india group (Read it here). He says…
In my application i have a datagrid with itemrenderer as charts and I need have to perform two operations - one on single click and one on double click - on the chart. But most of the times double click event is not fired and if fired then single click is also fired. Can I stop single click event if double click event is fired ?
I investigated this and found this to be true. Once you enable doubleClick (by setting the doubleClickEnabled flag), whenever it occurs, a click event is also fired with it… I discussed this with Sreeni and he said that this is because the framework intends not to skip any event (because a double click is actually a click followed by a doubleClick event).
This may be useful in a lot of cases, but in Arpan’s case, this was causing havoc. The way to work around this is to write a Timer/Interval and use it to work around the problem. The following is the execution path…
- On click, in the click handler, reset and initiate the timer which on complete, calls the deferredClickHandler (where the actual clickHandler code sits
- If doubleClick does not occur, the timer completes and then executes the deferredClickHandler (I have kept my timer to be 300 mS)
- If doubleClick occurs, it goes to the doubleClick handler, where you clear the timer (so that timer does not complete and execute the deferredClickHandler) and execute the doubleClickHandler code…
Caution: Do not forget to save the initial click Event if you need it later..
In Arpan’s case… he needs to use itemClick and itemDoubleClick events (of type ListEvent) instead of click & doubleClick (of type MouseEvent), as it is a DataGrid. The code below handles the case for both a DG & a Button… I have used the setInterval() method to implement the timer, you may as well use the Timer class…
本文探讨了在Flex应用程序中如何正确处理DataGrid的单击与双击事件,通过使用计时器来区分这两种操作,并避免事件冲突。
394

被折叠的 条评论
为什么被折叠?



