2012-03-29 54 views
0

我想要在flex中监听高级数据网格的双击和双击事件。我已经给双击启用true,并在itemdoubleclick写入功能,但只有点击工作,但不itemdoubleclick.Can任何人请帮助我。 感谢如何在高级数据网格中点击和双击一起flex

+1

您肯定需要将代码添加到您的文章,否则将几乎不可能帮助你。 – AlBirdie 2012-03-29 08:54:13

+0

您必须双击网格 – Triode 2012-03-29 10:27:36

回答

2

你可能做了正确的事情,但在DataGrid不处理得很好的单击和双击,你可以用一种变通方法来做到这一点:

第一DataGrid的属性:

<s:DataGrid 
    dataProvider="{lista}" 
    click="click(event)"   
    doubleClickEnabled="true"  
    doubleClick="doubleClick(event)"> 

然后点击处理程序启动一个定时器,如果定时器成功终止单击事件被调度,否则如果你双击定时器停止,你处理双击事件...

一个前充足的是比什么都好......

// A timer used to check if is a single or doubleclick 
private var t:Timer; 
protected function click(event:MouseEvent):void 
{ // on single click you start a timer, the dalay 
    // is 500 but you can set what you prefer    
    t = new Timer(500,1); 
    t.addEventListener(TimerEvent.TIMER_COMPLETE, singleClick); 
    t.start(); 
} 

protected function singleClick(e:TimerEvent):void 
{ 
    // if the timer complete correctly this method is called and 
    // here you manage the single click event 
    t.removeEventListener(TimerEvent.TIMER_COMPLETE,singleClick); 
    trace("single click");    
} 

protected function doubleClick(event:MouseEvent):void 
{ 
    // on double click you remove the timer event listener and you stop it if it's running 
    // here you manage the double click event...  
    t.removeEventListener(TimerEvent.TIMER_COMPLETE,singleClick); 
    if (t.running) 
     t.stop(); 
     trace("double click"); 
} 

希望这有助于...

+0

doubleClick事件是否会干扰单击?我在我的移动应用程序中有一个doubleClick,按预期工作,没有这种解决方法,但我没有一个单击事件侦听器。 – AlBirdie 2012-03-29 13:27:46

+0

数据网格中的否是单击会干扰双..单击和双击添加一个eventlistener而没有上述解决方法,当您双击时,单击和双击处理程序都会被触发......使用单击处理程序在被解雇前等待达拉,如果双击被触发singleclick事件不会继续... – Marcx 2012-03-29 14:53:14

+0

我明白了。不知道。感谢您的澄清! – AlBirdie 2012-03-29 15:04:28