|
-
Impressive Click
Key is released
Just wondering if there is a way to code when a key is released. I am not talking about mouse release but more of arrow keys or even any key release. What would it look like?
-
something like this
code:
if(key.isDown(key.space) {
do stuff;
}
-
·»¤«·
onClipEvent (keyUp) {
}
might also help
>flashl!ght<
All the normal names were taken.
Ron Paul was right.
-
Impressive Click
Originally posted by clinton2
something like this
code:
if(key.isDown(key.space) {
do stuff;
}
No I am not talking about pressing keys, because I know how to do that. Maybe an example might help:
ex:
when the space bar is pressed than nothing happens. But when you release your character shoots his gun.
The reason for this question was when I was thinking about a way so that the player can't hold onto a key. Instead he would constantly have to keep pressing it, for whatever reason.
-
Senior Member
Thats odd, i dont know of any other way than something like this:
code: onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE)) {
down = true;
}
}
onClipEvent (keyUp) {
if (down == true) {
//put all your actions here
}
}
Maybe there is a better way, because I could see how that might eventually become slow and confusing.
-
umm key listeners should do stuff on key up, but i've never been able to use them, to do what i want.........
code: k = new Object();
k.onKeyUp = function() {
k_rc();
};
Key.addListener(k);
but i'm not sure how to get it to work for a specific key (such as space)
Last edited by Dr Warm; 11-16-2004 at 09:15 PM.
-
Impressive Click
I am confused
k.onKeyUp = function() {
k_rc();
}
how can you have keyUp when k is an object? Or is the key "k" being assigned a value? Sorry but can someone explain.
-
You are right Dr Warm. This is how you get it to work for the space bar.
code:
k = new Object();
k.onKeyUp = function() {
//here 32 is the key code for space bar
if (Key.getCode() == 32) {
//fire,shoot,etc
}
}
Key.addListener(k);
-
Zakarus's Tale Developer
Code:
k = new Object();
k.spacePressed = false;
k.onKeyDown = function()
{
if ( Key.isDown( Key.SPACE ) ) this.spacePressed = true;
else this.spacePressed = false;
}
k.onKeyUp = function()
{
if ( k.spacePressed )
{
// code
}
}
Key.addListener( k );
What that does:
It creates an object, k. The way an object works is it creates a variable that can have methods and properties. Properties are like the _x and _y of a movieclip. Methods are the functions the object can do. Like you can do movieClip.hitTest( stuff ). That is a method of the MovieClip object( sortof ). So this code basically assigns two methods and one property to the object k. The property basically is just a boolean value that says whether or not the space was pressed. The two methods are onKeyUp and onKeyDown, these methods know when to be called as that is coded into the compiler. We are just telling the compiler what to do when these events happen. The last line just tells the Key object that we want to give it a new listener.
Cheers,
~Zakarus2001
"Come human relieve yourself of the ignorance society has placed on your head" ~Zakarus 24:7
-
Hey, Zakarus2001, why the heck would you want to go through the trouble of using 'if' statements, variables, and the onKeyDown method when the swcAndrew just wants to check when the space bar is let go and not pressed? I'm confused. Is there an advantage to using a the spacePressed variable?
-
Zakarus's Tale Developer
*bows head in shame*
I posted that about the same time you did, so I didn't read your post before I posted( as it wasn't there yet. )
I've been using Flash since 4 and I had no idea there even WAS a Key.getCode method .
So no, andross_88, there is no befefit AT ALL to what I did, and your way is much better and cleaner. I've just never thought about it that much.
Thanks though, I learned something new about the Key object.
Cheers,
~Zakarus2001
"Come human relieve yourself of the ignorance society has placed on your head" ~Zakarus 24:7
-
Its okay man, no need to be ashamed.
At least you got something out of this post.
-
Impressive Click
just to clarify is:
code:
if (Key.getCode() == 32) {
//fire,shoot,etc
}
this is space bar right because I have never worked with getCode before.
-
this is space bar right because I have never worked with getCode before.
yep, of course you could always test it!
Thnx for the info ppl had always told me the way like Zakarus2001 did but i new there had to be a simpler way, my problem was using Key.isDown instead of Key.getCode() yay, i'm happy!!!
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
|