September 1, 2009

DoubleClick Event in Flash

In this tutorial we will be looking how to create a button with both the single click and double click functions.Here is the sample demo file .Test the with single click and double.The event (whether single or double clicked) will be displayed below the button)


Before we build it let's look at the theory behind it. .

The theory behind the button is very simple. In a single click, the user simply clicks once on the button to invoke an action.
In a double click, the user clicks twice within a predetermined time frame (in this case 5 frames) to invoke its action.
A button of this nature has then two possible outcomes. But the dilemma is how to stop the action on the single click being executed on the first click of the double click if you are using the same button? Simple, the single click actions are not executed until the predetermined time allocated to the double click has elapsed. Any additional click within that timeframe will execute the double click actions.

Let's Start

  1. Open the New Movie.Create the button using (ctrl+F8)
  2. Set the roll over and down effects to button.
  3. Make this button as a Movieclip, using F8
  4. Now double-Click the Movieclip ,you will get the button instance inside of Movieclip,Now Give the Instance name for button.For example "btn"'
  5. Now click the Movieclip on stage ,and open a ActionScript Panel using F9.
  6. Write the Following Code For Movieclip
onClipEvent (load) {
// CONSTANTS NEEDED:
// Minimum duration to be considered hold
hold_duration = 250;
// Minimum duration to be considered double-click
double_duration= 250;
btn.onPress = function() {
this._parent.clicked = true;//to check for single click
if (!this._parent.Launched) {
this._parent.Launched = true;
this._parent.onEnterFrame = function() {
if (!Timing && clicked) {
Timing = true;
_root.txtresult.text="Not yet clicked"
clicked = false;
numTimeStart = getTimer();

else if (Timing && !clicked && !Released && numTimeStart+hold_duration

_root.txtresult.text="clicked and Held"
Timing = false;
clicked = false;
Released = false;
} else if (Timing && clicked && numTimeStart+double_duration

_root.txtresult.text="Double Clicked"
Timing = false;
clicked = false;
Released = false;
} else if (Timing && Released && numTimeStart+double_duration
_root.txtresult.text="Just Clicked"

Timing = false;
clicked = false;
Released = false;
} else if (numTimeStart+double_duration
Timing = false;
clicked = false;
Released = false;
Launched = false;
delete this.onEnterFrame;
}
};
}
};
btn.onRelease = function() {
this._parent.Released = true;
};
}
Download Source file From here
 

About

we are doing all kind of web / standalone applications using Flash , FMS, PHP , XML , CSS , etc. we handle all projects starting from the initial design concept through the delivery of your personalized product. Our commitment to you is comprehensive and complete-aimed at satisfying your every need. We have the experience and the expertise to get the job done.

Site Info

we Currently handling web requirements and multimedia productions and we have the capability of cutting your web , graphics and multimedia expenses to a bare minimum without sacrificing professional quality or delaying production. Our focus is on the development of smart, successful ideas and we always strive to maintain the highest . we currently using following technologies Flash 8, Flash cs3,Actionscript 2 ,Action script 3 ,Flash Media server , PHP,AMFPHP,XML ,HTML ,CSS ,Photoshop

Text

Digizone, AnnaNagar East, Chennai, TamilNadu ,India. Please view our website for further details

Flash and photoshop resources FREE Download Copyright © 2009 Community is Designed by Bie