Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  DoubleClick event for movie clips and buttons

DoubleClick event for movie clips and buttons

By Ajay Pal Singh | Published 03/20/2006 | Beginner | Rating:
Ajay Pal Singh
Ajay's biography coming soon... 

View all articles by Ajay Pal Singh
Page 1 of 1
Tutorial details: DoubleClick event for movie clips and buttons
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.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent

Verification:
Enter the security code shown below:
img


Add comment

Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Related Articles
Attachments
Article Series
This article is part 1 of a 2 part series. Other articles in this series are shown below:
  1. DoubleClick event for movie clips and buttons
  2. Class For Genrating Random Number
Comments
  • Comment #1 (Posted by Nick - ndbrandt at hotmail.com)
    Rating
    I cannot download the .fla for the tutorial "Simple Double Click Event." It's a good tutorial but I need to see the .fla. Thanks for your time!
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.