B.7. Chapter 12 Exercise

This exercise asked for you to integrate keyboard events to trigger the paste functionality of the Chapter12_Paste sample. To do this, you'll need to use the KeyboardEvent class to listen for keystrokes. Take a look at Listing B-11, and you'll notice that the init() function is called on applicationComplete of the WindowedApplication tag. The init() function adds an event listener to the nativeApplication property of the application. This event listens for the KeyDown event and also has the third parameter set to True, which will intercept the key capture. If you leave out this property or set it to False, you will notice that the NativeMenu (on Mac) will be triggered by the KeyDown events. So if you do have a NativeMenu in your application with keyboard shortcuts attached, you will need to code for them, since the application will no longer handle them automatically. The event listener will trigger the onKeyDown() function whenever the keyboard is used when the AIR application is in use. Within the onKeyDown() function, there is some logic to evaluate the keys that have been pressed. If the key combination includes the controlKey and keyCode number 86 (the "V" key) on Windows or the commandKey and keyCode number 86 on Mac, the paste() function is called. From this point on, the application is exactly the same as the Chapter12_Paste example.

Example B-11. The solution file for the Chapter 12 Exercise
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.