Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-19-2009, 10:21 PM   #1
AndrewDude
Registered User
 
Join Date: Nov 2009
Posts: 4
Question KeyboardEvent - Kind of new?

Alright I'm new to Keyboard event listeners so I might be making a really obvious mistake that I don't know about. But what I want to do is, when someone types the letters for the word 'BROTHER', then it appears on the screen and it moves to the next frame.
Here's the code I have atm

I currently have the letters for 'BROTHER' each as a movie clip. The instance names are, RKey, OKey, etc.

ActionScript Code:
BKey.visible=false; RKey.visible=false; OKey.visible=false; TKey.visible=false; HKey.visible=false; EKey.visible=false; R2Key.visible=false; import flash.events.KeyboardEvent; //keycodes var b:uint = B; var r:uint = R; var o:uint = O; var t:uint = T; var h:uint = H; var E:uint = E; stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener); function keyDownListener(e:KeyboardEvent) { if (e.keyCode == b){ BKey.visible=true;} if (e.keyCode == r){ RKey.visible=true; R2Key.visible=true;} if (e.keyCode == o){ OKey.visible=true;} if (e.keyCode == t){ TKey.visible=true;} if (e.keyCode == h){ HKey.visible=true;} if (e.keyCode == E){ EKey.visible=true;} if (BKey._visible && R2Key._visible && RKey._visible && OKey._visible && TKey._visible && HKey._visible && EKey._visible) { gotoAndStop(26); } }

Here's the problem I'm getting though.
1120: Access of undefined property B.
var b:uint = B;

1120: Access of undefined property R.
var r:uint = R;

1120: Access of undefined property O.
var o:uint = O;
etc. (goes on to other letters as well)

Now, is this the only mistake in my thing? Or are there more mistakes? How do I fix it?

Thanks!

Last edited by AndrewDude; 11-19-2009 at 10:27 PM.
AndrewDude is offline   Reply With Quote
Old 11-20-2009, 12:27 AM   #2
BeerOclock
Member
 
Join Date: Feb 2009
Posts: 90
Default

var b:uint = B;


uint stands for unsigned integer. B is not an integer, thats why you're having problems.

Google for the ASCII values of letters and you'll find that
A = 65
B = 66
C = 67
...

etc
BeerOclock is offline   Reply With Quote
Old 11-20-2009, 03:21 AM   #3
sugarengine
Registered User
 
Join Date: Feb 2009
Posts: 17
Default

Use the ASCII values, and also consider using a switch statement instead of all those If structures.

Way cleaner.
sugarengine is offline   Reply With Quote
Old 11-20-2009, 04:54 PM   #4
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,819
Send a message via Skype™ to henke37
Default

He does not need the ASCII values. He needs the virtual keyboard key codes. Most are defined in the Keyboard class, but only the AIR player can read them directly (how stupid). Just read them yourself and use them directly in your script.
henke37 is offline   Reply With Quote
Old 11-22-2009, 06:30 PM   #5
AndrewDude
Registered User
 
Join Date: Nov 2009
Posts: 4
Default

Thanks! The ASCII codes worked great!
How do switch statements work though?
AndrewDude 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:30 PM.

///
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.