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
- Open the New Movie.Create the button using (ctrl+F8)
- Set the roll over and down effects to button.
- Make this button as a Movieclip, using F8
- Now double-Click the Movieclip ,you will get the button instance inside of Movieclip,Now Give the Instance name for button.For example "btn"'
- Now click the Movieclip on stage ,and open a ActionScript Panel using F9.
- 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();
}
// 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
_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;
};
}