-
I tried...
disable key
Is there a way to disable a keyboard key after you press.
As in, if you press and hold, it will only execute the action for that key once.
on (press, keyPress "<Left>") {
\\somehow disable the key
this.gotoAndPLay("walk");
}
Thanks for your help.
-
Code:
on (press, keyPress "") {
if (disabled != true) {
this.gotoAndPLay("walk");
disabled = true;
}
}
on (release, keyRelase) {
disabled = false;
}
I might have made up the 'keyRelease' handler ... you'd need to check it out. But that should work, in theory.
----------
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." TERRY PRATCHETT
-
I tried...
Thanks, that works.
How do you enable the key (and play a certain frame) when you release the key?
The keyRelease does not work.
Thanks.
-
Okay ... take the code off the button, make the button into a movieClip, then put this code on the movieClip:
Code:
onClipEvent (load) {
disabled = false;
}
onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse, _root._ymouse, true && disabled != true) {
this.gotoAndPLay("walk");
disabled = true;
}
}
onClipEvent (keyDown) {
if (disabled != true) {
this.gotoAndPLay("walk");
disabled = true;
}
}
onClipEvent (mouseUp) {
disabled = false;
}
onClipEvent (keyUp, mouseUp) {
disabled = false;
}
----------
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." TERRY PRATCHETT
-
I tried...
there are syntax errors that i dont know how to fix.
i fixed the one on line 5, but can't figure out what's wrong on line 19, it says there is a unexpected ")", but i can't find it.
-
Code:
onClipEvent (load) {
disabled = false;
}
onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse, _root._ymouse, true) && disabled != true) {
this.gotoAndPlay("walk");
disabled = true;
}
}
onClipEvent (keyDown) {
if (disabled != true) {
this.gotoAndPlay("walk");
disabled = true;
}
}
onClipEvent (mouseUp) {
disabled = false;
}
onClipEvent (keyUp) {
disabled = false;
}
Apologies ... try that.
----------
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." TERRY PRATCHETT
-
I tried...
Thanks for the code.
is there a way to specify a key for the KeyDown and keyUp functions, that will still work with the code?
-
Yes, but what had you in mind? It's difficult to code without knowing exactly what you wanted.
----------
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." TERRY PRATCHETT
-
I tried...
All i'm trying to do is to make a guy walk forward, but when you hold down the key, it keeps in going back to the beginning frame of the movie clip without playing it all the way through, so i thought disabling the key would be the best way to do that, and when you release the key, it would enable it again. But if there is a easier way to make the guy walk, please tell me. Thanks.
-
Yes, there is a SLIGHTLY easier way ...
Code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) && this._currentframe < this._totalframes) {
nextFrame();
}
}
Put that code on the movieClip of the 'walking' action, and when you press the left arrow key on the keyboard it will start walking. Let the key go and it will stop.
----------
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." TERRY PRATCHETT
-
I tried...
I should have probably said that the walk movie clip is inside another movie clip. Sry about that.
Would that affect the code even if i changed the onClipEvent to the "load".
-
Put the code I posted above ON THE CLIP CONTAINING THE ANIMATION. Doesn't matter what else is going on around it ... just make sure that code is on the actual movieClip.
----------
"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." TERRY PRATCHETT
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|