PDA

View Full Version : double press?



kpxnamja
October 2nd, 2006, 12:36 AM
I've come to a stumbling point.
How do you have flash recognize a double pressed key from a single press?
Similar to a double click on a window program opening the software, and a single click selecting the program. How would you program flash to do a similar detection?

For instance, if I have a MC named "hero" and I want it to move casually with these simple movement scripts:


_root.hero.onEnterFrame = function() {
if (Key.isDown(87)){
movement = "up";
this._y -= _root.speed;
}
if (Key.isDown(83)){
movement = "down";
this._y += _root.speed;
}
if (Key.isDown(65)){
movement = "left";
this._x -= _root.speed;
}
if (Key.isDown(68)){
movement = "right";
this._x += _root.speed;
}
}


However, if the "up" (87) is double pressed I want it to move double times the speed for a short second.

Is there any suggestions for this function?

LittleFenris
October 2nd, 2006, 09:07 PM
Check out this link:

http://www.kirupa.com/forum/showthread.php?t=206904&highlight=double+click+class

That should help.

kpxnamja
October 2nd, 2006, 10:05 PM
Excuse me for the asking incorrectly. I meant a double keyboard press/click not a double mouse click.

So I want it to detect a double <space> press as oppose to a sinlge <space> press.

SacrificialLamb
October 3rd, 2006, 01:51 AM
it's the same idea swope MouseDown with Key.isDown, you might need to Key.addListener but it will work

Pepin
October 4th, 2006, 01:41 AM
This works well. Just modify the variables. If the fps if set to 30 then the person has 1/3 of a second to double click.

onClipEvent (load) {
c = 0;
}

onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
if (!down){
c += 20;
down = true;
}
} else {
down = false;
}

if (c>30) {
this._rotation = 90;
}
if (c>0){
c -= 1;
}
trace (c);
}