[AS3]as3单击与双击事件完美解决方法附源代码(3)
importflash.display.Sprite; importflash.events.*; importflash.utils.Timer; publicclassMyButtonextendsSprite { publicvardouble:Boolean; publicfunctionMyButton(){ super(); init(); } publicfunctioninit(
- import flash.display.Sprite;
- import flash.events.*;
- import flash.utils.Timer;
- public class MyButton extends Sprite
- {
- public var double:Boolean;
- public function MyButton() {
- super();
- init();
- }
- public function init():void {
- addEventListener( MouseEvent.CLICK , onClickHandler );
- addEventListener( MouseEvent.DOUBLE_CLICK , onDoubleClickHandler );
- }
- public function onClickHandler( e:MouseEvent ):void {
- double = false;
- var timer:Timer = new Timer(260,1);
- timer.addEventListener( TimerEvent.TIMER , checkClick );
- timer.start();
- }
- public function onDoubleClickHandler( e:MouseEvent ):void {
- double = true;
- }
- public function checkClick( e:TimerEvent ):void {
- if( double ){
- //www.cuplayer.com酷播提示你监听这两个自定义事件即可
- dispatchEvent( new Event( "mouseDoubleClick" , true ) );
- }else{
- dispatchEvent( new Event( "mouseSingleClick" , true ) );
- }
- }
- }
以上的做法有个弊端,就是会导致单击延时.
高手推荐做法
只加CLICK的侦听,然后通过记时然后分辨单击和双击
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...