Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-24-2005, 08:23 PM   #1
crazylegsmurphy
Registered User
 
Join Date: Feb 2005
Posts: 94
Default Keypress....Sorry, I know it's probably been posted a bunch.

Hey,

I'm sorry, I know this has probably been posted a million times, but I am just not understanding the concept of this keypress code.

I am simply just trying to get a user to be able to press the button with the mouse, or use a keypress.

The trouble I am having is that I can't figure out how to get the keypress to work for a letter such as "T" or "D" for example.

I have this code...
ActionScript Code:
on (release) {     _root.gotoAndStop("TOOLS MENU 01"); }
But I am at a loss past that.

Thanks for your help!

Jeff

Last edited by CyanBlue; 02-24-2005 at 08:53 PM. Reason: AS tag is applied
crazylegsmurphy is offline   Reply With Quote
Old 02-24-2005, 08:37 PM   #2
Doccie
Flashin'
 
Doccie's Avatar
 
Join Date: May 2004
Location: Belgium
Posts: 326
Default

well, to see if a key is pressed, you need to check the key's keycode first.
so, first off, use a trace, like this.
ActionScript Code:
trace(Key.getCode());
Then test your movie and press the T-key for instance. The output window will show what keycode the T-key has.

After that, use this code.
ActionScript Code:
if(Key.isDown(78)){ // 78 being the code of the key that you want people to press, so change it with the code you got from the trace     gotoAndStop("TOOLS MENU 01"); }
__________________
If you send me a Private Message, pls do not ask for a reader's receipt. I will not send you one anyway.

Doccie is offline   Reply With Quote
Old 02-24-2005, 08:42 PM   #3
crazylegsmurphy
Registered User
 
Join Date: Feb 2005
Posts: 94
Default cool

I see what you are saying.

Does this work in Projector? (I am making this a standalone movie)

I tried what you said, but it doesn't seem to get the code...unless that TRACE needs to be on frame 1 or something.

Thanks agian,

Jeff

(Here is the error Code)

**Error** Scene=Scene 1, layer=Tools Button, frame=1:Line 2: Statement must appear within on handler
if(Key.isDown(78)){ // 78 being the code of the key that you want people to press, so change it with the code you got from the trace

Total ActionScript Errors: 1 Reported Errors: 1

Last edited by crazylegsmurphy; 02-24-2005 at 08:45 PM. Reason: More info
crazylegsmurphy is offline   Reply With Quote
Old 02-24-2005, 08:46 PM   #4
Doccie
Flashin'
 
Doccie's Avatar
 
Join Date: May 2004
Location: Belgium
Posts: 326
Default

It seems you have to add the code to a movieclip (same with the key.isDown code)
ActionScript Code:
onClipEvent(keyDown){     trace(Key.getCode()); }
That should work
__________________
If you send me a Private Message, pls do not ask for a reader's receipt. I will not send you one anyway.

Doccie is offline   Reply With Quote
Old 02-24-2005, 08:51 PM   #5
crazylegsmurphy
Registered User
 
Join Date: Feb 2005
Posts: 94
Default

hmm,

So then if I have this correct...you need to add a blank movie clip with the
ActionScript Code:
onClipEvent(keyDown){         trace(Key.getCode()); }
And then...for the button...that is where I am confused, are you saying add a movie clip in a layer within the button?

Last edited by CyanBlue; 02-24-2005 at 08:53 PM. Reason: AS tag is applied
crazylegsmurphy is offline   Reply With Quote
Old 02-24-2005, 09:51 PM   #6
Doccie
Flashin'
 
Doccie's Avatar
 
Join Date: May 2004
Location: Belgium
Posts: 326
Default

To click the button you just use the on(release) event which you already mentioned in your first post.
For the keypresses you just add the code I added earlier to an empty movieclip anywhere on the stage.
ActionScript Code:
onClipEvent(enterframe){ if(Key.isDown(78)){ // 78 being the code of the key that you want people to press, so change it with the code you got from the trace         gotoAndStop("TOOLS MENU 01"); } }
__________________
If you send me a Private Message, pls do not ask for a reader's receipt. I will not send you one anyway.

Doccie is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:20 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.