Be a Supporter!

Simple press of a key

  • 292 Views
  • 8 Replies
New Topic Respond to this Topic
mooseisloose
mooseisloose
  • Member since: Dec. 6, 2004
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Simple press of a key 2008-07-31 17:25:33 Reply

It's late at night and I'm having trouble thinking...

Simple AS2.0 problem...

if (_root.submachine=2;){
//what would I put here so that when the "2" key is pressed... this.gotoAndStop(2);
}

thanks guys =] i should really get some sleep but my friend keeps bugging at me to get on with this game so yeah... don't want to dissapoint =p

Super-Yombario
Super-Yombario
  • Member since: Mar. 16, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Simple press of a key 2008-07-31 17:31:38 Reply

umm...

if(Key.isDown(2)){

That SHOULD work.

Insanimation
Insanimation
  • Member since: Feb. 27, 2008
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to Simple press of a key 2008-07-31 17:36:46 Reply

At 7/31/08 05:31 PM, Super-Yombario wrote: umm...

if(Key.isDown(2)){

That SHOULD work.

I thought it should be:

if(Key.isDown(Key.2)){

That's what I'd have done...it certainly works for moving MCs. eg.

onClipEvent(enterFrame) {
if(Key.isDown(Key.RIGHT)) {
this._x+=5
}
}

Not sure why I included that code, but I felt that it proved my point...your code may work too, and if it does, its better...


GOTPENMUSTFLASH!

BBS Signature
K-Guare
K-Guare
  • Member since: May. 23, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Simple press of a key 2008-07-31 17:37:35 Reply

if (_root.submachine==2){

First off, you need to use '==' because your checking a value,
and you need to get rid of the semicolon, you don't need it inside of there.

Here's the whole thing:

onEnterFrame = function() {
// That makes this check perform on every frame
	if (_root.submachine == 2) {
		if(Key.isDown(2)){
			gotoAndStop(2);
		}
	}
}

what

BBS Signature
mooseisloose
mooseisloose
  • Member since: Dec. 6, 2004
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to Simple press of a key 2008-07-31 17:39:04 Reply

At 7/31/08 05:31 PM, Super-Yombario wrote: umm...

if(Key.isDown(2)){

That SHOULD work.

okay so now I have:

if (_root.submachine=2;){if(Key.isDown(2)){
this.gotoAndStop(2);}}

which is probably right, it looks wrong to me but im too tired to think properly) but now it says i'm missing a ')' somewhere... *cough*.......... ermmmm......... yeah..... help please! xD

also in case anyone says it, yes i do know that i *might* have to change the 2 with the keycode for the 2 key... i probably sound like a general dick like now but i dont care because i dont even know what im typing =D

zrb
zrb
  • Member since: Aug. 8, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Simple press of a key 2008-07-31 17:39:12 Reply

At 7/31/08 05:31 PM, Super-Yombario wrote: if(Key.isDown(2)){
That SHOULD work.

Lol the keycode for the 2 key is not 2, 2 is the keycode for the right mouse button.

Anyways moose, here's the right code:
if (_root.submachine==2){
//what would I put here so that when the "2" key is pressed... this.gotoAndStop(2);
if (Key.isDown(50)) {
gotoAndStop(2);
trace("Your pressing 2");
}
}
Here's the list of keycodes :)


School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature
mooseisloose
mooseisloose
  • Member since: Dec. 6, 2004
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to Simple press of a key 2008-07-31 17:45:52 Reply

thanks guys, mixed up a few of your answers. i was screwing up on small things like the semicolon and whatnot... but yeah all fixed now thanks to everyone that lended a helping hand =]

K-Guare
K-Guare
  • Member since: May. 23, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Simple press of a key 2008-07-31 17:47:49 Reply

At 7/31/08 05:39 PM, zrb wrote: Lol the keycode for the 2 key is not 2, 2 is the keycode for the right mouse button.

Shit, that means my code is wrong!
I barely know any of the key codes, so i just
assumed what he said was correct.
Should have done my homework :[

Here's the damn thing, OP.

onEnterFrame = function() {
	if (_root.submachine == 2) {
		if (Key.isDown(50)) {
			gotoAndStop(2);
		}
	}
}

what

BBS Signature
zrb
zrb
  • Member since: Aug. 8, 2006
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Simple press of a key 2008-07-31 17:47:49 Reply

At 7/31/08 05:45 PM, mooseisloose wrote: thanks guys, mixed up a few of your answers. i was screwing up on small things like the semicolon and whatnot... but yeah all fixed now thanks to everyone that lended a helping hand =]

Out of curiosity, what exactly were you trying to do ?
Prevent right-clicking or an action for the "2" key on the keyboard ?


School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature