PDA

View Full Version : Error 1119 while trying to check if Enter key is pressed?



JMowery
April 29th, 2007, 03:14 PM
txt_input.addEventListener(KeyboardEvent.KEY_UP, eventResponse);

function eventResponse(event:Event):void
{
if(event.keyCode == Keyboard.ENTER)
{
trace("Enter Key Pressed!");
}
}


stop();
txt_input is a text input field on the stage.

I am running Flash CS3, and am new to actionscript and such, but I have been trying to get that code to work, and in examples, it shows that it works, but, I for some reason get the following error:

1119: Access of possibly undefined property keyCode through a reference with static type flash.events:Event.



I have searched the internet for hours, and the closest thing I have found is that I have to do some sort of casting thing or something, but I'm not sure how to do this.

The only result that came up was in this forum, with the casting thing, so help on how to properly do that is what I need.


So if anyone has an idea as to how to fix this, I'd be much appreciative :)

stringy
April 29th, 2007, 03:25 PM
try


function eventResponse(event:KeyboardEvent):void
{ //etc

JMowery
April 29th, 2007, 03:32 PM
try
ActionScript Code:

function eventResponse(event:KeyboardEvent):void
{ //etc






Awesome, that works perfectly....

That's weird, the example on the Flex 2 page has it as just (event:Event), and it works correctly, but it doesn't work in Flash CS3.

So does that mean the documentation in Flex 2, with the sample is just written incorrectly?


Thanks for the help again, works great.

stringy
April 29th, 2007, 03:39 PM
Awesome, that works perfectly....

That's weird, the example on the Flex 2 page has it as just (event:Event), and it works correctly, but it doesn't work in Flash CS3.

So does that mean the documentation in Flex 2, with the sample is just written incorrectly?


Thanks for the help again, works great.
Glad it worked :)
I have never used flex so sorry i just don`t know.

Dazzer
April 29th, 2007, 08:46 PM
Basically the reference is old. And CS3 IDE probably has strict typing on.

Its not an error. Its a warning. But since you're on strict mode, it decide to kill the compilation anyway.

Since "KeyCode" is a property of KeyboardEvent, while you could technically type it as an Event (which is the superclass of all event classes), you cannot call the property KeyCode, as the compiler does not know whether it is defined or not. So to reduce the risk of a NULL value, it forces you to type correctly.

That and the reference contains alot of booboos. :)

skyp
April 30th, 2007, 12:36 AM
thanks, I learned something here too.=)