views:

297

answers:

2

Hello,

My goal is to know when a user presses the cut, copy, paste, or select all keyboard shortcuts and do some processing for each one. I tried listening for the keypresses, but only some keys are fired when the control key is down (apparently it would work only in the browser, except for IE).

Then I was reading the Flash docs and came across the Event.COPY, Event.PASTE, and Event.CUT events that are dispatched to the "object that currently has focus". I attached listeners to the document class for these events and set stage.focus to the document class, but my event listeners never get called.

Has anyone used these events? Is there an example somewhere on how to use them?

Note: This is in Flash Player 10 (both the internal CS4 one (with "Disable Shortcuts" checked off) and the stand-alone one). I have not tried it in any browser.

A: 

Beside the restriction of not beeing able to capture such events from TextFields (or when the focus is on a TextField), make sure that the stage.focus property is indeed set to the InteractiveObject you attached the listeners to, or any of its childs (unless its a textfield ^^).

Bear in mind that you can only set the focus by directly setting the stage.focus property, and by clicking or tabbing on tabEnabled InteractiveObjects.

Cay
You're right -- as it turns out I did set stage.focus, but because of circumstances unique to my application (I had to click on a certain area before doing anything), the focus changed and my events would never be heard from again. I fixed this with a (very) crude but effective solution: I listen for the focusOut event, and then set stage.focus to my InteractiveObject that has the event listeners. I'll have to figure something else out later though, because this probably won't work when I have dynamic TextFields :-)
Cameron
A: 
Cameron