如何在高级datagrid flex中一起单击并双击

时间:2012-03-29 05:28:51

标签: actionscript-3 flex flex4 flex3

我想在flex中收听高级数据网格的点击和双击事件。我已经双击启用了true并在itemdoubleclick中编写了该函数,但只有点击工作但不是itemdoubleclick.Can任何人请帮助我。 感谢

1 个答案:

答案 0 :(得分:2)

你可能做对了,但是数据网格不能很好地处理点击和双击,你可以使用变通方法来做到这一点:

首先是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");
}

希望这会有所帮助......