详细内容
flash课件制作中应用到的鼠标双击效果制作方法
flash课件制作中应用到的鼠标双击效果制作方法
flash课件制作用法:
建立一个空的MC并与该类链接,然后把这个MC放到主场景中,取个名字(本例为myDbClick),在主场景的第一帧加上以下代码:
var myDbClick:MovieClip;
var myObj = new Object();
myObj.onDbClick = function(evtObject:Object):Void{
//trace(evtObject.target);
//在此书写你的代码
}
myDbClick.addEventListener("onDbClick", myObj);
import mx.events.EventDispatcher;
class DbClick extends MovieClip {
private var firstClickTime:Number;
private var lastClickTime:Number;
private var n:Number = 0;
private var dispatchEvent:Function;
private static var _mixin1 = EventDispatcher.initialize(DbClick.prototype);
function DbClick() {
}
private function onLoad():Void {
var onwer:Object = this;
_root.onMouseDown = function(){
onwer.ifDbClick();
}
}
private function ifDbClick():Void {
if ( n == 0 ){
n = 1;
firstClickTime = getTimer();
}else{
n = 0;
lastClickTime = getTimer();
}
//两次点击时间差在300毫秒以内计为双击
if ( Math.abs(lastClickTime - firstClickTime) < 300 ) {
//trace("double click");
//发出事件
this.dispatchEvent({ type:"onDbClick", target:this });
}
}
}