Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

keyCode Keyboard Events

Participant ,
Aug 20, 2007 Aug 20, 2007
The following code is giving me an error 1119:

function keyPressed(event:Event):void {
if (event.keyCode == Keyboard.ENTER) {
mainText.text = myGreeter.sayHello(textIn.text);
}
}

The error says Access of possibly undefined property keyCode through a reference with static type flash.events.Event if(keyCode == Keyboard.ENTER).

Should the double equals sign (equality) be a single one?
TOPICS
ActionScript
886
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 21, 2007 Aug 21, 2007
That is because your function is receiving and event of type Event. I believe the type should be KeyboardEvent.

Translate
Mentor ,
Aug 20, 2007 Aug 20, 2007
I'm not positive, and I can't test this, but the keyCode for the enter button is 13 so what if you try

if(event.keyCode == 13){

or
if(event.keyCode == Keyboard.13){
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 21, 2007 Aug 21, 2007
No, that didn't work. The error I'm getting now is 1119: Access of possibly undefined property keyCode through a reference with a static type flash.events.Event. This code comes from Adobe's PDF entitled Programming ActionScript 3.0.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 21, 2007 Aug 21, 2007
LATEST
That is because your function is receiving and event of type Event. I believe the type should be KeyboardEvent.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines