Defect and improvement of custom mouse double click event

Source: Internet
Author: User
Tags sleep
Mouse last night want to write a mouse double-click event, always feel that the code has seen before (finally think it seems to be JS inside ...). According to the habit of writing a ondbclick, found incredibly do not change color?! Dizzy, so change OnDoubleClick, ondouble ... And so do not change color, flash does not define this event?! In anger, to find help, there is no ...
And then came up to search the Flash bar on the mouse double-click on the post, a look n many ah, are their own write function to achieve (again angry), but still Holybozo code is the most concise, and then dragged down to use. The problem is found in the use of time, as long as within the delay, I crazy 10 times to trigger the 9 events, and according to common sense should be two times one, that is, if every two times between the time is not more than the delay, the point 10 should only produce 5 events (I This truth is not ah, hehe), so start to change the algorithm ...
The following are the possible clicks (the representative clicks, _ represents the delay interval, ___ represents more than the delay):
_ ___ _ ___....
___ _ ___...
_ _ ___ _ ....
....
...... In my long attempt, the first thing I thought of was setting signs, double-click to complete once on the flag, and finally did not, only to achieve the separation between the delay time of two double double-click, _ ___ _, and if it is the point of the word will only trigger an event _ _ _ _ _ ... So depressed for a night, sleep did not sleep well, the total feeling is OK, just did not think out ...
Positive solution: In the morning to decide to change a method, at a glance to see lastclicked this time variable, so in the code riga when the completion of a double click 0,hoho, Successful ... (A little excited), here's the code:

var j=0;
var lastclicked=0;
Movieclip.prototype.dbclick=function (Time) {
if (time==undefined) time=500;
if ((Lastclicked-(Lastclicked=gettimer ()) +time>0)) {
Trace ("Time true");
Lastclicked=0;
return true;
}
return false;
}
_root.onmousedown=function () {
Trace (j + +);
if (Dbclick (250)) {
Trace ("Double click");
}
}
Logo bit of really can't think out, twisted up chaos of death ... It seems that logical thinking needs more training.

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.