Quick tutorial on opening Web Notifications in compatible browsers (Webkit) via as3.

First download the WebNotifications.swc and include it in your project.

import net.peteshand.utils.WebNotifications;

If you want to test if the users browser is compatible simply call:

if (WebNotifications.available){
    // do something
}

Once you’ve checked if WebNotifications is available you can open a basic notification with the following code:

if (WebNotifications.available){
    WebNotifications.Open(title, body, iconURL, timeout);
}

You can also open an html page within a notification with the following code:

if (WebNotifications.htmlAvailable){
	WebNotifications.OpenHTML(url, timeout);
}

You can close open notifications with the following code:

if (WebNotifications.htmlAvailable){
	WebNotifications.Close(id);
}

Where id is either the title or the url depending on the type of notification.
You can also close all open notifications with the following code:

if (WebNotifications.htmlAvailable){
	WebNotifications.CloseAll();
}

An example can be viewed below:

WebNotifications

Get Adobe Flash player

download example source

Known Limitations:
* Custom icons are not supported in OSX
* HTML Notifications are not supported in OSX
* CloseAll() and Close(id) are not supported in OSX
* Timeout is not supported in OSX (default timeout time set by OS to 5 seconds)
* For the eventlisteners to work correctly, the ‘name’ parameter must be set in attributes object to the same as the swfobject replaceElemIdStr or equivalent if something other than swfobject is being used to embed the flash. Eg: “altContent”

var flashvars = {};
var params = { menu: "false", scale: "noScale", allowFullscreen: "true", allowScriptAccess: "always", wmode: "direct" };
var attributes = { id:"WebNotifications", name:'altContent' };
swfobject.embedSWF("WebNotifications.swf", "altContent", "440px", "400px", "10.0.0", "expressInstall.swf", flashvars, params, attributes);



Public Properties:
WebNotifications.available : Boolean
[static] [read-only] A Boolean value that determines if web notifications are available.

WebNotifications.htmlAvailable : Boolean
[static] [read-only] A Boolean value that determines if html web notifications are available.

WebNotifications.eventListenersAvailable : Boolean
[static] [read-only] A Boolean value that determines if event listeners are available.

WebNotifications.permissions : String
[static] [read-only] returns permission status, ‘allowed’, ‘not allowed’, ‘denied’, ‘unavailable’

WebNotifications.permissionsVal : int
[static] [read-only] returns permission status, 0, 1, 2, -1

Public Methods:
WebNotifications.Open(title:String, body:String, icon:String, timeout:int=10);
[static] Opens a basic web notifications

WebNotifications.OpenHTML(URL:String, timeout:int=10);
[static] Opens an html web notifications

WebNotifications.Close(id:String);
[static] Closes web notifications with specified ID, the id is either the title, or url depending on the type of notification.

WebNotifications.CloseAll();
[static] Closes all web notifications

WebNotifications.requestPermission(callback:Function);
[static] requests permissions and callback is fired once the user clicks allow or deny

If you find any bugs, or have questions comment away.