PDA

View Full Version : Button click vs. button hold


Huecifer
10-06-2010, 08:48 PM
Hello,

I'm trying to make a button I have on my "home" frame perform two functions:

1: on a click (quick press) gotoAndStop at the "doggie" frame.
and
2: on a press and hold, gotoAndPlay at the "kitty" frame.


I have it sort-of functional using this code (that I found searching the interwebs):

stop();

var minTime = 0;
var intervalID:Number;

power_mc.onPress = function() {
function callback() {
minTime = getTimer();
}
intervalID = setInterval(callback, 100);
};

power_mc.onRelease = function() {
if (minTime<100) {
gotoAndPlay("doggie");
} else {
gotoAndPlay("kitty");
}
clearInterval(intervalID);
minTime = 0;
};

The problem with this is that I can't seem to get the "timer" on the button to stop: I will quick-click and go to the "doggie" frame, which plays a short sound. Then, when I go back to the home frame, if I quick-click again it sends me to the "kitty" frame, as if the minTime>100.

Any ideas on how to fix this? Or, is there more appropriate code I should be using?

Huecifer
10-07-2010, 01:12 PM
Fixed!

I should have thought of this before, but I simply changed the object and instance name of the button/mc on the doggie and kitty frame. That seems to have reset the time each time I revert to the home frame. Great success!