A.7. DockIcon and SystemTray

AIR allows us to customize the dock icon on Mac and the system tray icon on Windows at runtime. This means that even when our application is not in focus, we still have the ability to alert users of important information about our application. We also have the ability to make the dock icon bounce to get the user's attention and force the user to move focus to our application. The following code will create a custom dock icon by using the image returned from the Yahoo weather service and layering the current temperature on top. The icon will be recreated each time a new image is loaded by listening for an update event of the img object within the Results view.

To implement the DockIcon and SystemTray icons, please perform the following steps. Add an import statement to the WeatherAIR.mxml file:

import mx.events.FlexEvent;

Set up an event listener within the init() function of WeatherAIR.mxml by adding the line below to the init() function.

resultsView.img.addEventListener(FlexEvent.UPDATE_COMPLETE,setDockIcon);

Next add the setDockIcon() method to the WeatherAIR.mxml file. This method will be called each time the weather image changes. It creates a new BitmapData object by reading the bytes of the <mx:Image> object holding the weather image and the <mx:Text> object holding the current temperature. This new BitmapaData object is then passed into the NativeApplication.nativeApplication.icon.bitmaps array.

private function setDockIcon(event:FlexEvent):void{ ...

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.