Skip to main content
Participating Frequently
September 16, 2009
Question

Navigating different movieclips on the same stage with arrow keys while mouse is over movieclip

  • September 16, 2009
  • 3 replies
  • 448 views

How can I navigate (prevframe and nextframe) three different movieclips on the same stage by using the arrow keys (up and down, or left and right)?  I would like to go frame by frame of one movie clip while the mouse is hovering over it.  If a user moves the mouse over a different movieclip on the same stage the arrow buttons then would navigate that particular movieclip.

Any suggestions are appreciated.

Is it possible to add an event listenter for a mouse-over function and then add another event listener for a keyboard event?  Can you group an event listener within an event listener?

Furna

This topic has been closed for replies.

3 replies

Inspiring
September 16, 2009

NOTE: Ned's suggestion is a correct one. I just wanted to point out that depending on your case you may want to utilize commonalities of events.

Because KeboardEvent and MouseEvent extend Event - you can reuse the same listener for both types of interaction:

myButton.addEventListener(MouseEvent.CLICK, myEventHandler);

addEventListener(KeyboardEvent.KEY_DOWN, myEventHandler);

myClip.addEventListener(MouseEvent.MOUSE_OVER, myEventHandler);

function myEventHandler(e:Event):void{

     trace("event type = " + e.type);

     trace("target = " + e.target);

     trace("currentTarget = " + e.currentTarget);

     trace(e is MouseEvent);

     trace(e is KeyboardEvent);

}

Inspiring
September 16, 2009

ok I'm not sure this would work but I guess you can do that... you need to get the code for the up and down keys and then add keyboard events listeners to them...

Ned Murphy
Legend
September 16, 2009

Yes, you can add listeners for mouse over and mouse out that add and remove keyboard event listeners, respectively.  The keyboard event handler function could be written such hat it uses a variable to target whichever movieclip is being hovered, that variable being set by the mouse over event handler.