Flex中判断单击还是双击的方法
Flex中,在双击事件时,单击事件也会同时相应,需要解决双击时,单击事件应该被屏蔽,这个是个问题,但是有解决方案
?
?
今天偶尔看到了这个方法,供大家参考,它是利用时间差来鉴别是单击还是双击:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
??????? layout="absolute"
??????? width="900" height="538"
??????? click="clickScreen(event)" doubleClick="dblScreen(event)" keyDown="keyDown(event)"
???????? doubleClickEnabled="true">
??????? <mx:Script>
??????????????? <![CDATA[
??????????????????????? private var intervalID:Number = 0 ;
??????????????????????? private var timeOffset:Number = 300 ;
???????????????????????
??????????????????????? public function fullScreenClick(event:MouseEvent):void{
??????????????????????????????? trace("fullScreenClick1");
??????????????????????? }
???????????????????????
??????????????????????? public function clickScreen(event:MouseEvent):void{
??????????????????????????????? clearInterval(intervalID);
??????????????????????????????? intervalID = setInterval(doClick,timeOffset);
???????????????????????
??????????????????????? }
???????????????????????
??????????????????????? private function doClick():void
??????????????????????? {
??????????????????????????????? trace("one click");
???????????????????????
??????????????????????? clearInterval(intervalID);
???????????????????????
??????????????????????? }
???????????????????????
??????????????????????????????? public function dblScreen(event:MouseEvent):void{
??????????????????????????????? clearInterval(intervalID);
??????????????????????????????? trace("double click");
??????????????????????? }
??????????????????????????????? public function keyDown(event:KeyboardEvent):void{
??????????????????????????????? trace("key down");
??????????????????????? }
???????????????????????
??????????????? ]]>
??????? </mx:Script>
</mx:Application>