Flash判断双击之记时法

2015-08-18 15:22:22来源:作者:人点击

第七城市

下面是代码:

class devil.com.btn.original.DoubleClick {
/**
Set up an Object to citing a object(btn or mc ) clicked
*/
private var _clickedObject:Object;
/**
Set up an ID
*/
private var _ID:Number;
/**
Set up a delay time
*/
private var _delayTime:Number = 200;
/**
Record counts obj is clicked
*/
private var _count:Number = 0;
/**
Chageing _delayTime property
*/
public function set delayTime(delay:Number):Void {
_delayTime = delay;
}
public function get delayTime():Number {
return _delayTime;
}
/**
Set up a instance
*/
public function DoubleClick(delayTime:Number) {
this._delayTime = delayTime;
}
/**
When button or movieclip is clicked this click method is called
*/
public function click(obj:Object) {
if (this._clickedObject == undefined) {
_clickedObject = obj;
}
if (_count == 0) {
//first click
timerStart();
_count = 1;
} else {
this._clickedObject.onDoubleClick();
//双击
_count = 0;
}
}
/**
Timer star
*/
private function timerStart():Void {
clearInterval(_ID);
_ID = setInterval(this, "timerStop", _delayTime);
}
/**
Timer stop
*/
private function timerStop():Void {
clearInterval(_ID);
if (_count == 1) {
_clickedObject.onClick();
//单击
_count = 0;
}
}
}

下面是用法:

import devil.com.btn.original.DoubleClick;
var b:DoubleClick = new DoubleClick(200);
b.onClick = function() {
//单击要执行的函数
trace("单击")
};
b.onDoubleClick = function() {
//单击要执行的函数
trace("单击")
};
b.onDoubleClick=function(){
//双击
trace("双击")
}
b.onRelease=function (){
_root.a.click(this)}

第七城市

相关文章

    无相关信息

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台