|
-
[RESOLVED] case Keyboard.ENTER works, why not case Keyboard.anyletter?
Hi gang, first off I want to say that I completed my app development program certificate through the University of Washington this past week, and I got through a couple of sticky areas thanks only to the helpful members of Flashkit boards. I am very thankful. 
With 9 months of curriculum in my head, it seems that I've really only scratched the surface of AS.
My current project, one I came up with after being inspired by this fellow's drum playing app (http://travisroof.com/coastdrums.html) is to let the user strum notes in a guitar A minor pentatonic scale. I've recorded the notes and have progressed to the point where I'm programming the actual note playing.
I've decided that while playing a guitar via mouse click may sound cool I think it'd be better to wire the notes up via keyboard. And I have hit a snag that I don't understand.
Actionscript Code:
loA.addEventListener(MouseEvent.CLICK, playLowA); loC.addEventListener(MouseEvent.CLICK, playLowC); loD.addEventListener(MouseEvent.CLICK, playLowD);
etc...
Actionscript Code:
function playLowA(evt:MouseEvent):void{ if(channel){ channel.stop(); channel = blLowA.play(); } else { channel = blLowA.play(); } }
function playLowC(evt:MouseEvent):void{ if(channel){ channel.stop(); channel = blLowC.play(); } else { channel = blLowC.play(); } }
etc...
That's how the mouseclick function/events work. No problem. Having 12 separate notes as their own functions may seem belabored, but it satisfies Programmers Rule #1: It Works.
Here's how I'd like to have it set up:
Actionscript Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, playKeyboardNote);
function playKeyboardNote(evt:KeyboardEvent):void { switch(evt.keyCode){ case Keyboard.ENTER: if(channel){ channel.stop(); channel = blLowA.play(); } else { channel = blLowA.play(); } break; case Keyboard.BACKSPACE: if(channel){ channel.stop(); channel = blLowC.play(); } else { channel = blLowC.play(); } break; } }
But instead of ENTER and BACKSPACE I want to use my own key assignments, namely Q W E R T Y U I O P[ ]
And the 'intellisense' capability in Flash CS4 shows that it is a possibility: when typing dozens of key choices are available, including regular ol' letters...
So why doesn't
Actionscript Code:
case Keyboard.Q: if(channel){ channel.stop(); channel = blLowA.play(); } else { channel = blLowA.play(); } break;
work for me in this script?
If Keyboard.ENTER is a valid option, why isn't Keyboard.Q?
And yes, when testing the movie, I do choose 'Disable keyboard shortcuts.'
And, though i don't know if it's important, I include this at the top:
Actionscript Code:
import flash.ui.Keyboard;

This is gonna be one howling cool app. I've recorded the pentatonic scale in a regular bluesy amp effect, and I've got a shredding metal-like amp effect recorded ready to go, as well. I also plan to have a backing track option, so the user can play out their own little guitar solo.
Thanks very much
Don
Last edited by brainSalad; 06-20-2010 at 04:50 PM.
Reason: clarification of code
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|