-
keyboard event problem
function mkey (event:KeyboardEvent)
{
}
function mkey (event:MouseEvent)
{
}
this.addEventListener(KeyboardEvent.KEY_DOWN, mkey);
mbutton.addEventListener(MouseEvent.CLICK, mbut);
I created a simple keyboard event that makes an object move. The problem I'm having is that when I try this out in the player the flash doesn't recieve any Keyboard events until I click an object that I made use a mouse event.
basically I have to click on the mbutton object for the keyboard events to be recognised.
Should I set a focus or what?
-
Senior Member
Your function names are the same. The last function will override the previous one.
- The right of the People to create Flash movies shall not be infringed. -
-
Oops, I didn't mean to write the functions that way when I posted. Assuming that the function names are different. Would flash look for the mouse listener before the keyboard listener?
function mkey (event:KeyboardEvent)
{
}
function mbut (event:MouseEvent)
{
}
this.addEventListener(KeyboardEvent.KEY_DOWN, mkey);
mbutton.addEventListener(MouseEvent.CLICK, mbut);
-
Setting focus to the object is the ONLY way it can receive keyboard events. If you click it, you are setting it's focus. If you want to capture keyboard events without having to set focus, add the listener to the stage object.code: this.stage.addEventListener(KeboardEvent.KEY_DOWN, whatever);
-
Thank you, that is exactly what I was looking for. I assumed that 'this' would have implied that it was the stage.
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
|