Nov
2
Flash ActionScript Detect Mouse Press and Hold
November 2, 2008 |
While doing a Flash ActionScript catalogue project, I was required to differentiate mouse click and mouse press and hold event. So to differentiate mouse click and mouse press and hold, we have to extend default Flash ActionScript functions.
To find a solution, we must first identify the difference click and press and hold
It’s the time that how long the press occurred, so when onPress, we need to create a timer to see how long it lasted before onRelease occurs. Assume you have an MovieClip called my_mc on stage, on the action layer, type the following ActionScript:
var minTime = 0;
var intervalID:Number;
my_mc.onPress = function() {
function callback() {
minTime = getTimer();
}
intervalID = setInterval(callback, 100);
this.startDrag();
};
my_mc.onRelease = function() {
this.stopDrag();
if (minTime<100) {
trace(”click ended”);
} else {
trace(”press and hold ended”);
}
clearInterval(intervalID);
minTime = 0;
};
The Output panel will trace “click ended” if the press lasts less 0.1 second, and trace “press and hold ended” if the press lasts more than 0.1 second.
Hope this helps!
Similar Posts
- Flash Upload Mac Problem Fix
- JavaScript Control Flash Replay
- Flash Ball Collision Prevent Stick and Rotate
- No Flash Replace with Image
- Flash ActionScript Detect Get Image Width Height
- Make HTML Elements Appear on Top of Flash Movie
- ComboBox Dropdown Popup List Appears Behind
Comments
2 Comments so far



































This really helped me tremendously, thank you so much for the post!
Thanks the author!