Flex单击与双击

因为Flex AS3双击前会先调一遍单机,所以需要特殊处理。

使用Timer延迟判断是单击双击。

 

使用Timer时,接收到的对象已经由MouseEvent对象变为TimerEvent对象了,所以需要在外部定义一个数据对象,保存MouseEvent对象中传递的数据。

 

line.addEventListener(MouseEvent.CLICK, clickLineHandle);
line.doubleClickEnabled = true;
line.addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickLineHandle);
line.toolTip="单击展示服务调用详情\n双击展示服务明细";

 

var isDoubleClick:Boolean  =  false ;//判断是否是双击的标志
		var _line:SequenceLine = null;
		public function clickLineHandle(event:MouseEvent):void
		{			
			isDoubleClick  =  false ;  
			_line = event.currentTarget as SequenceLine;
			var timer:Timer  =  new  Timer(260, 1);  
			timer.start();//也就是说两次单击间隔在260毫秒之内的就被认为是双击  
			timer.addEventListener(TimerEvent.TIMER, clickOrDouble);		
		}
		
		
		public function doubleClickLineHandle(event:MouseEvent):void
		{			
			isDoubleClick  =  true ;  
			_line = event.currentTarget as SequenceLine;			
		}
		
		private function clickOrDouble(event:TimerEvent):void {  
			var data:EsbServiceProCusV = _line.data as EsbServiceProCusV;	
			_line = null;
			if(isDoubleClick){  
				var evt:FlashDynamicEvent=new FlashDynamicEvent(FlashDynamicEvent.EVENT_LINE_DOUBLECLICK, true);
				evt.data= data.id;
				this.dispatchEvent(evt);
			}else{  
				var evt:FlashDynamicEvent=new FlashDynamicEvent(FlashDynamicEvent.EVENT_LINECLICK, true);
				evt.data= data.serviceNameEn;
				this.dispatchEvent(evt);
				
			}  
		}

 

//////////////////////////////////////////////////////////////////////

以下为自定义事件及后续处理:

package  com.event
{

	import flash.events.Event;

	dynamic public class FlashDynamicEvent extends Event
	{		
		public static  const EVENT_LINECLICK:String="lineClick";		
		
		public static  const EVENT_LINE_DOUBLECLICK:String="lineDoubleClick";		
		
		public var data:Object=new Object();
		
		public var event:Event;

		public function FlashDynamicEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(type, bubbles, cancelable);
		}
	}
}

 

//mxml页面接收:
_sequenceView.addEventListener(FlashDynamicEvent.EVENT_LINECLICK, lineClickHandle);
_sequenceView.addEventListener(FlashDynamicEvent.EVENT_LINE_DOUBLECLICK, lineDoubleClickHandle);


public function lineClickHandle(event:FlashDynamicEvent):void
{
	var serviceNameEn:String = event.data as String;		
	_applicationView.GetURLRequest.addEventListener(ResultEvent.RESULT, urlRequestResultHandle);
	_applicationView.GetURLRequest.addEventListener(FaultEvent.FAULT, errorHandle);
	//获取urlRequest地址				
	_applicationView.GetURLRequest(serviceNameEn,0);
}

public function lineDoubleClickHandle(event:FlashDynamicEvent):void
{
	var serviceId:Number = event.data as Number;		
	_applicationView.GetURLRequest.addEventListener(ResultEvent.RESULT, urlRequestResultHandle);
	_applicationView.GetURLRequest.addEventListener(FaultEvent.FAULT, errorHandle);
			
	_applicationView.GetURLRequest(null,serviceId);
}

 

参考:Flex中区分单击和双击的方法

[ActionScript 3] 关于屏蔽双击事件中的单击事件的讨论

Flex Timer 定时器

 

 

你可能感兴趣的:(Flex)