下面是代碼:
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)}