一个网友写的鼠标双击类

2006-05-20 11:37:53

import mx.utils.Delegate; import mx.core.UIObject; class DBClick { public static var DELAY_TIME:Number =&nb sp;200; private var _mc:UIObject; private var intervalID:Number; private var delayTime:Number; public function DBClick(mc:UIObject) { _mc = mc; _mc.onMouseUp = Delegate.cr&#101;ate(this, onClick ); } private function onClick() { if (!delayTime) { delayTime = getTimer(); if (intervalID != undefined) { clearInterval(intervalID); } intervalID = setInterval(this, "run", DE LAY_TIME); } else { if ((getTimer()-delayTime)<DELAY_TIME) { _mc.dispatchEvent({target:_mc, type:'onDClick'}); } delayTime = null; } } private function run():Void { if (delayTime) { _mc.dispatchEvent({target:_mc, type:'onClick'}); delayTime = null; clearInterval(intervalID); } } public static function init(mc:UIObject) ;{ var dClick = new DBClick(mc); } } 使用方法: -------------------- import DBClick; DBClick.init(_btn); _btn.addEventListener("onDClick", this); _btn.addEventListener("onClick", this); function onDClick() { _btn.label="你刚才双击了我" } function onClick() { _btn.label="你刚才单击了我" } 很好用的。