Nov

2

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

Comments

Name (required)

Email (required)

Website

Speak your mind

2 Comments so far

  1. mbanavige on November 3, 2008 6:46 am

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

  2. EncundNon on December 19, 2008 7:35 pm

    Thanks the author!

Sponsors




Links