Wednesday, April 6, 2011

Working with windows in AIR: Part 11

Today we will learn how to notify the user that a window in your AIR application needs to be viewed, for example, if your application is an instant messenger and somebody sent the user a new message.

When we send a notification to the user, he sees that the window needs to be opened when it is minimized (for example, it starts blinking in Windows). Here's how you do it:

Firstly, we need to pick a window that will be the one that the user is notified of. In this example it is the main application window:

var mainWindow:NativeWindow = NativeApplication.nativeApplication.openedWindows[0];

I'll set a timer that sends notifications every 3 seconds.

var myTimer:Timer = new Timer(3000);
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.start();

To notify the user, we use the method notifyUser(), which has one parameter that needs to be passed - the type of the notification. It can be NotificationType.INFORMATIONAL and NotificationType.CRITICAL.

function onTimer(TimerEvent):void
{
mainWindow.notifyUser(NotificationType.CRITICAL);
}

And the full code:

import flash.display.NativeWindow;
import flash.desktop.NativeApplication;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.desktop.NotificationType;

var mainWindow:NativeWindow = NativeApplication.nativeApplication.openedWindows[0];

var myTimer:Timer = new Timer(3000);
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.start();

function onTimer(TimerEvent):void
{
mainWindow.notifyUser(NotificationType.CRITICAL);
}

Thanks for reading!

Related:

Working with windows in AIR: Part 1
Working with windows in AIR: Part 2
Working with windows in AIR: Part 3
Working with windows in AIR: Part 4
Working with windows in AIR: Part 5
Working with windows in AIR: Part 6
Working with windows in AIR: Part 7
Working with windows in AIR: Part 8
Working with windows in AIR: Part 9
Working with windows in AIR: Part 10
Working with windows in AIR: Part 12

No comments:

Post a Comment