Sarath
Sarath

Reputation: 9156

How can i prevent default behaviour of key events in as3

I have a video player , and its using a slider.While the video is playing i press the right-arrow or left-arrow , it tries to move the slider pointer. I need to call a function insted of the default behaviour.

stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);

function myKeyDown(e:KeyboardEvent):void{

switch(e.keyCode)
        {
        case 37:
                callLeft();
                break;
        case 39:
                callRight();
                break;
                        ......
                        ..
            }
}

But the functions are not being called when i press the keys, instead its calling the default actions.Enter key also have problems. How can i fix that.

Upvotes: 1

Views: 2582

Answers (1)

Chunky Chunk
Chunky Chunk

Reputation: 17237

function myKeyDown(e:KeyboardEvent):void
{
     e.preventDefault();
     ...

Upvotes: 3

Related Questions