Forum Topic: i need help with keys

(146 views • 17 replies)

This topic is 1 page long.

<< < > >>
Questioning

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 06:01 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

i have question about keys:
how to make a code thet if i pressed key 'W' the player will go to frame 2 and if i will hold Key 'W' it will go to frame 6?


None

WolfAkela

Reply To Post Reply & Quote

Posted at: 8/15/08 06:08 AM

WolfAkela LIGHT LEVEL 08

Sign-Up: 12/19/05

Posts: 2,327

this.onEnterFrame = function(){
if(Key.isDown(yourkeycode)){
}
}

yourownkeycode list:
http://spamtheweb.com/ul/upload/150808/6 5891_keygetter2hw.php

Just replace yourkeycode with the key code that appears on the link. Click it, press a key.


None

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 07:28 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

At 8/15/08 06:08 AM, WolfAkela wrote: this.onEnterFrame = function(){
if(Key.isDown(yourkeycode)){
}
}

yourownkeycode list:
http://spamtheweb.com/ul/upload/150808/6 5891_keygetter2hw.php

Just replace yourkeycode with the key code that appears on the link. Click it, press a key.

I KNOW THE CODES BUT HOW TO MAKE A CODE THET SAY-if you hold the key?


Misunderstood

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 08:12 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

plz help me with thet...


Misunderstood

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 08:55 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

plz help me...


None

SAGGAMES

Reply To Post Reply & Quote

Posted at: 8/15/08 09:36 AM

SAGGAMES DARK LEVEL 06

Sign-Up: 08/10/08

Posts: 58

just create a variable to do it for you
onClipEvent(enterFrame){
if(Key.isDown("what ever W is on the ascii code")){
if(pressed==true){
gotoAndStop(6)
}else{
pressed=false
}
}else{
gotoAndStop(1)
}
}

By the way, I realise that that script could easily be optimised, but i am just keeping it simple, in case you are not all that "flash" with scripting


None

LonLonRanch

Reply To Post Reply & Quote

Posted at: 8/15/08 09:42 AM

LonLonRanch LIGHT LEVEL 17

Sign-Up: 05/22/05

Posts: 320

I don't really see your problem doing:

this.onEnterFrame = function(){
  if(Key.isDown(yourkeycode)){
     //your code
  }
}

Does count it for being held down. The isDown() method is checking to see if the Key is Down, so technically it is checking if it is 'held down.'

If you're getting problems with it, it may be better to post the code you're having trouble with


None

KyleDaFox

Reply To Post Reply & Quote

Posted at: 8/15/08 10:00 AM

KyleDaFox LIGHT LEVEL 25

Sign-Up: 04/23/05

Posts: 2,144

I would do something along the lines of the way before with the variable, but a bit different.

onLoad = function(){
holdvar = 0
}
onEnterFrame = function(){
if(Key.isDown(87)){
holdvar++
}
if(holdvar>=1 && (holdvar <=9 && (!Key.isDown(87)))){ //------------------ Change the 9 if you want a shorter time to count as if you just press it.
	_root.gotoAndStop(2)
}
if(holdvar>=10 && (!Key.isDown(87))){ //------------------ If you change the 9 in the few lines above, you have to make this 10 one number above it.
	_root.gotoAndStop(6)
}
}

It calls a variable equaling 0, and when the key is down, it adds. You can change numbers in the lines marked with ------------ to get say maybe you want a shorter time to be counted as pressed than 10.

If you want to see how this works, make 6 frames, on the first frame, put

stop();

, copy and paste the code i gave you above, and make a dynamic text box with the variable holdvar (YOU DO NOT NEED THIS DYNAMIC TEXT BOX, IT'S JUST TO VISUALLY SHOW WHAT IT DOES).

On the 2nd frame, put the number 2, and on the 6th frame, put the number 6.

You will see the 0 add by 1 when W is down.

Questions? Feel free to ask.

Check out my newest News Post!
Anyone need an artist or coder for a game? Drop me a PM!

BBS Signature

Angry

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 10:26 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

the key acii code or whatever the name is means if key is hold?
and i ASKED ABOUT IF YOU HOLD THE KEY!i know if(Key.isDown){ thing!-i asked about if YOU HOLD THE KEY!!!


None

WolfAkela

Reply To Post Reply & Quote

Posted at: 8/15/08 10:29 AM

WolfAkela LIGHT LEVEL 08

Sign-Up: 12/19/05

Posts: 2,327

Key.isDown() does tell Flash if you're holding a key.

And please, stop screaming.


Mad as Hell

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 10:30 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

At 8/15/08 10:29 AM, WolfAkela wrote: Key.isDown() does tell Flash if you're holding a key.

And please, stop screaming.

ya but there is if the key is pressed and if you still holding the key!


None

LonLonRanch

Reply To Post Reply & Quote

Posted at: 8/15/08 10:34 AM

LonLonRanch LIGHT LEVEL 17

Sign-Up: 05/22/05

Posts: 320

I'm starting to think you don't know what you're talking about. there is no isHeld(); function or anything of the sort. isDown(); is what everyone uses, if you can't figure out how to use it to your desire then I'm sorry, but you there is no reason to get mad at people who are trying to help you.


None

KyleDaFox

Reply To Post Reply & Quote

Posted at: 8/15/08 10:34 AM

KyleDaFox LIGHT LEVEL 25

Sign-Up: 04/23/05

Posts: 2,144

At 8/15/08 10:26 AM, DevCho wrote: the key acii code or whatever the name is means if key is hold?
and i ASKED ABOUT IF YOU HOLD THE KEY!i know if(Key.isDown){ thing!-i asked about if YOU HOLD THE KEY!!!

Yes, I did that with a variable, there is no thing inside of flash that tells if it holds the key, just try out my code, I tested it, it works.

Check out my newest News Post!
Anyone need an artist or coder for a game? Drop me a PM!

BBS Signature

None

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 10:43 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

At 8/15/08 10:34 AM, KyleDaFox wrote:
At 8/15/08 10:26 AM, DevCho wrote: the key acii code or whatever the name is means if key is hold?
and i ASKED ABOUT IF YOU HOLD THE KEY!i know if(Key.isDown){ thing!-i asked about if YOU HOLD THE KEY!!!
Yes, I did that with a variable, there is no thing inside of flash that tells if it holds the key, just try out my code, I tested it, it works.

i tried but it isn't work -only when i hold the 'W' key and realesed it....i ment in the time its holding not on reales....


None

KyleDaFox

Reply To Post Reply & Quote

Posted at: 8/15/08 10:51 AM

KyleDaFox LIGHT LEVEL 25

Sign-Up: 04/23/05

Posts: 2,144

I'm thinking to do what you want, just take out the second && (!Key.isDown(87))){

onLoad = function(){
holdvar = 0
}
onEnterFrame = function(){
if(Key.isDown(87)){
holdvar++
}
if(holdvar>=1 && (holdvar <=9 && (!Key.isDown(87)))){ //------------------ Change the 9 if you want a shorter time to count as if you just press it.
	_root.gotoAndStop(2)
}
if(holdvar>=10){ //------------------ If you change the 9 in the few lines above, you have to make this 10 one number above it.
	_root.gotoAndStop(6)
}
}

Try that, you aren't quite clear on what you want.

Check out my newest News Post!
Anyone need an artist or coder for a game? Drop me a PM!

BBS Signature

None

DevCho

Reply To Post Reply & Quote

Posted at: 8/15/08 11:03 AM

DevCho NEUTRAL LEVEL 02

Sign-Up: 07/24/08

Posts: 53

it doesn't metter if im taking out the second !Key.isDown its still not working...
i ment thet you need to hold 'w' key-as long as you holding him it will go to frame 6 but if you pressing key 'W' just pressing not holding it will go to frame 2!


None

rickeyricksricky

Reply To Post Reply & Quote

Posted at: 8/15/08 09:44 PM

rickeyricksricky LIGHT LEVEL 03

Sign-Up: 08/12/08

Posts: 83

At 8/15/08 11:03 AM, DevCho wrote: it doesn't metter if im taking out the second !Key.isDown its still not working...
i ment thet you need to hold 'w' key-as long as you holding him it will go to frame 6 but if you pressing key 'W' just pressing not holding it will go to frame 2!

Ya need to hold the "W" n' release it if your usin' Kyle's script.


None

WhoknowsmeaUdiO

Reply To Post Reply & Quote

Posted at: 8/24/08 03:19 PM

WhoknowsmeaUdiO DARK LEVEL 13

Sign-Up: 04/11/07

Posts: 1,168

At 8/15/08 11:03 AM, DevCho wrote: it doesn't metter if im taking out the second !Key.isDown its still not working...
i ment thet you need to hold 'w' key-as long as you holding him it will go to frame 6 but if you pressing key 'W' just pressing not holding it will go to frame 2!

I just made this, i am sure it works.

onClipEvent (load) {
	counter = 0
	framerate = 12
	//change the framerate var so it matches your actual framerate
}
onClipEvent (enterFrame) {
	if(Key.isDown(87)){
		counter ++
		setcharge = true
	}
	if(!Key.isDown(87)&& counter > framerate){
		_root.gotoAndStop(3)
		counter = 0
	}
	if(!Key.isDown(87)&& counter < framerate && setcharge == true){
		setcharge = false
		counter = 0
		_root.gotoAndStop(2)
	}
	if(!Key.isDown(87)&& counter < framerate){
		counter = 0
		setcharge = false
	}
}

Check this for more key codes for AS2!

In case you haven't noticed yet, this isn't my main anymore. PM me here.

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 06:09 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!