DoubleClick event for movie clips and buttons

Page 1 of 1
Tutorial name: Simple Double Click Event
Written by: Ajay Pal Singh, email: ajaybalyan (followed by @ followed by) gmail DOT com
Difficulty Level: Beginner
Requirements: Flash MX 2004
This tutorial is based on ActionScript 2.0, as i have seen a number of tutorial on double click, some of these use jumping to a diffrent frame others use complex coding. This one is an example of making DoubleClick event as simple as it is.
By using setInterval(); the CPU speed hardly matters the exicution of code. Here DC is the button on which DoubleClick event is applied and reset is for reseting the movie
Download source FLA "DoubleClick.fla"
First of all i Should illustrate what is happening on _root
var clickCounter:Number = 0;
var clickTimer:Number = 0;
var timerID:Number;
function checkStatus() {
clickCounter++;
if (clickCounter == 1) {
timerID = setInterval(clickDuration, 250);
}
if (clickCounter == 2) {
this.btnDC.enabled = false;
this.animation.gotoAndStop("State2");
clickCounter = 0;
clickTimer = 0;
clearInterval(timerID);
}
}
function resetBtn() {
clickCounter = 0;
clickTimer = 0;
this.btnDC.enabled = true;
this.animation.gotoAndStop("State1");
}
function clickDuration() {
clickTimer++;
if (clickTimer == 2) {
clearInterval(timerID);
resetBtn();
}
}
This code is written on the first frame of Movie (i.e._root) it has three functions checkStatus(), resetBtn() and clickDuration. Let us see what these functions do one by one
1. checkStatus()
This function deals with Number of clicks made on Instance, also the custom Action to be performed by the event is specified in same function.
We have declaired three variables all of Number Type
I. clickCounter counts the Number of Clicks made on instance which is initialized to 0.
II. clickTimer deals with the duration in which you want DoubleClick to be valid, it is also initialized to 0.
III. timerID is an interval ID used to set and clear the interval.
In first line of this function we have incremented the clickCounter becouse this function is called on click event of the button. Now as wehave to count time from first click to second click so a timer is initalized on click 1. On click 2 the custom action is performed along with clearing the variables and clearing the Interval as well.
2. resetBtn()
This function deals with reseting the variables and button, it works with RESET button and also if Second click is made after Maximum Duration
for DoubleClick.
3. clickDuration()
Here we are simply countin the time in microseconds and ensures that asthe maximum duration is crossed all variables and Movie clip is reseted
Now about Movie clips, HEY thats peace of cake, these functions are called with Mouse Events.
Spread The Word
Article Series
This article is part 1 of a 2 part series. Other articles in this series are shown below:
-
DoubleClick event for movie clips and buttons
Attachments
6 Responses to "DoubleClick event for movie clips and buttons" 
|
said this on 04 Mar 2007 3:08:39 PM CST
I cannot download the .fl
|
|
said this on 11 Jan 2010 8:09:19 AM CST
I am easy understanding
i need more new update thanks everybod |
|
said this on 19 Feb 2010 5:40:05 PM CST
...and another very ease
var pres = 0; btn. p if(pres == 1){ } else { trace("you } } function timeOut( pres = 0; clearInt } |
|
said this on 08 Jun 2011 11:50:43 AM CST
Your solution is much eas
|
|
said this on 26 Jun 2010 7:53:29 AM CST
thanks it's working 100%
|
|
said this on 10 Sep 2011 6:10:33 AM CST
@Val: Elegant solution.
|


Author/Admin)