Mouse to see a lot of forums on the double click event posts, wrote a AS2 class put up for everyone's reference.
Demonstrate: http://home.goofar.com/Blog_/flash/DbClick.swf
Class Name: dbclick.as
Code
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 ();
}
Two-click time difference within 300 milliseconds is a double click
if (Math.Abs (Lastclicktime-firstclicktime) < 300) {
Trace ("Double click");
Issue an Event
This.dispatchevent ({type: "Ondbclick", target:this});
}
}
Usage
Create an empty MC and link to the class, then put the MC in the main scene, take a name (this example is Mydbclick), and add the following code to the first frame of the main scene:
var Mydbclick:movieclip;
var myobj = new Object ();
Myobj.ondbclick = function (evtobject:object): void{
Trace (Evtobject.target);
Write your code here
}
Mydbclick.addeventlistener ("Ondbclick", myobj);
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