Flash ActionScript code: mouse Double click class

Source: Internet
Author: User
Mouse/**
* @author Sonygod
*/
Import Mx.events.EventDispatcher;
Class DBMC {
private Var Time1:number;
private Var Time2:number;
public Var addeventlistener:function;
public Var removeeventlistener:function;
public Var dispatchevent:function;
private static var _mixin1 = Eventdispatcher.initialize (Dbmc.prototype);
public Var Owen:movieclip;
Public Function DBMC (Mc:movieclip, Show:boolean) {
Trace ("Loading ...");
Owen = MC;
Owen.usehandcursor = Show;
Eventdispatcher.initialize (Owen);
MCDB ();
}
Public Function mcdb () {
owen.onpress = function () {
time1 = Gettimer ();
Gets the time that the key was pressed
Gets the key value that is pressed
------------Double click Detect----------------
The first condition is to check the double-click Time, as long as the interval in 150 milliseconds is counted double-click, you can increase or decrease the time interval by personal preference. The second condition is that the same key is pressed two times
if (time1-time2<150) {
This.dispatchevent ({type: "Ondbclick", target:this});/double-click
}else{
This.dispatchevent ({type: "OnClick", target:this});/click
}
};
Owen.onrelease = function () {
Time2 = Gettimer ();
};
}
}

Use:
/**
* @author Sonygod
*/
var bb:dbmc = new DBMC (mc,false);
var myobj = new Object ();
Myobj.ondbclick = function (evtobject:object): Void {
Trace ("Double *********************");
};
Myobj.onclick = function (evtobject:object): Void {
Trace ("click *********************");
};
Bb.owen.addEventListener ("Ondbclick", myobj);
Bb.owen.addEventListener ("OnClick", myobj);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.