Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-30-2012, 04:30 AM   #1
Sammi Luu
Registered User
 
Join Date: Feb 2011
Posts: 12
Default how to disable tab and delete keys of the computer keyboard?

Hi everyone -

Okay so I have a piano game. User can press the following keys of the computer keyboard (1,2,3..-,=,q,w,e..[,],\) except tab and delete.

Is there a way to disable the computer keyboard function?

Thanks in advance!

Code:
//RUN WHEN A KEYDOWN EVENT OCCURS
//CHECKS KEYCODE, PLAYS CORRESPONDING NOTE AND PUTS NOTE IN DOWN POSITION
		public function pressNote1(event:KeyboardEvent):void {
		
			switch (event.keyCode) {
				 
				case 9 : //tab
					trace("C");
					if (n0Down == false) {
						n0Down = true;
						soundList[0].play(); 
						piano2.n0.gotoAndStop("down");
					}
					break;
				case 49 : //key 1
					trace("C#_Db");
					if (n1Down == false) {
						n1Down = true;
						soundList[1].play(); 
						piano2.n1.gotoAndStop("down");
					}
					break;
				case 81 : //key q
					trace("D");
					if (n2Down == false) {
						n2Down = true;
						soundList[2].play(); 
						piano2.n2.gotoAndStop("down");
					}
					break;
                               case 46 : //key delete
					trace("A#_Bb");
					if (n22Down == false) {
						n22Down = true;
						soundList[22].play(); 
						piano2.n22.gotoAndStop("down");
					}
					break;

//RUN WHEN A KEYUP EVENT OCCURS 
//CHECKS KEYCODE AND PUTS NOTE IN UP POSITION
public function releaseNote1(event:KeyboardEvent):void {
			
			switch (event.keyCode) {
				//tab
				case 9 : piano2.n0.gotoAndStop("up"); n0Down = false; break;
				//key 1
				case 49 : piano2.n1.gotoAndStop("up"); n1Down = false; break;
				//key q
				case 81 : piano2.n2.gotoAndStop("up"); n2Down = false; break;
				//key delete
				case 46 : piano2.n22.gotoAndStop("up"); n22Down = false; break;
Sammi Luu is offline   Reply With Quote
Old 04-30-2012, 09:16 AM   #2
Biodiscus
Immma firing Ninnnnjaaa
 
Join Date: Aug 2011
Posts: 95
Default

http://www.leebrimelow.com/?p=3311
Biodiscus is offline   Reply With Quote
Old 04-30-2012, 11:56 AM   #3
Nandha
Senior member
 
Join Date: Aug 2008
Location: Chennai,India
Posts: 38
Send a message via ICQ to Nandha Send a message via MSN to Nandha Send a message via Yahoo to Nandha Send a message via Skype™ to Nandha
Default

addEventListener(KeyboardEvent.KEY_DOWN, preventKey, true);
public function preventKey(evt:KeyboardEvent):void
{
evt.stopImmediatePropagation();
evt.stopPropagation()
}
Nandha is offline   Reply With Quote
Old 05-01-2012, 03:49 PM   #4
Sammi Luu
Registered User
 
Join Date: Feb 2011
Posts: 12
Default

Thanks for your response Nandha. Sorry for the late reply, i was sick.

I applied your code and I received this error: #1006: stopImmediatePropagation is not a function.

Any suggestion on solving this issue?

public function playBtnClicked(e:MouseEvent): void
{
infoBtn.visible = true;
infoBtn.mouseEnabled = true;
infoGame3.visible = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressNote1);
stage.addEventListener(KeyboardEvent.KEY_UP, releaseNote1);

addEventListener(KeyboardEvent.KEY_DOWN, preventKey, true);




}

public function home2BtnClicked(e:MouseEvent):void {
main_class.show_home();
}

public function preventKey(e:KeyboardEvent):void
{
//tab
piano2.n0.stopImmediatePropagation();
piano2.n0.stopPropagation();

//delete
piano2.n22.stopImmediatePropagation();
piano2.n22.stopPropagation();
}
Sammi Luu is offline   Reply With Quote
Old 05-02-2012, 01:39 AM   #5
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,820
Send a message via Skype™ to henke37
Default

Pay more attention to what object the method is invoked on. It is invoked on the event object and nothing else.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 05-02-2012, 01:52 PM   #6
Poony
Senior Member
 
Poony's Avatar
 
Join Date: Aug 2011
Location: Sweden
Posts: 387
Default

The event object is passed to the event handler function, and you've named the parameter "e", where Nandha named his "evt".
ActionScript Code:
e.stopImmediatePropagation(); e.stopPropagation();
Poony 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 03:42 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.