Tag Archives: example

Using Growl in AIR applications with AIR 2 NativeProcess

The AIR2 release is just around the corner and one of my favorite new features is the ability to use native scripts. As I’ve already demonstrated earlier, this is extremely powerful and here’s another good example.

From the moment AIR was released, a lot of developers were asking for Growl support to add toast style notifications. Up until now, there hasn’t really been an easy and flexible solution so most developers opted to build their own notifications. I really like Growl and the fact that you as a user have total control over the look and feel. I use the Mono style created by Christopher Lobay. It’s probably the sexiest toast style notification I’ve ever used.

With AIR 2 you can now call Growl right from within your application. I actually call the Growlnotify command-line tool, which comes as an extra in the Growl download. Most people probably don’t install these extras but that’s no problem. I can bundle the command-line tool as part of my application and call it directly from my applicationDirectory.

So… How does this work? It’s actually extremely easy… The first thing you do is set up a new File object that points to the Growlnotify tool.

var file:File = File.applicationDirectory;
file = file.resolvePath("growlnotify");

As I am going to bundle growlnotify with my application it will just be installed as part of the app and thus resides in applicationDirectory.

The next thing I have to do is set up a NativeProcessStartupInfo object. That’s where I’ll store the basic information that is used to start our NativeProcess.

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var processArgs:Vector.<String> = new Vector.<String>();
processArgs[0] = "-n";
processArgs[1] = "My AIR application";
processArgs[2] = "-p";
processArgs[3] = "0";
processArgs[4] = "-t";
processArgs[5] = "Your Growl title";
processArgs[6] = "-m";
processArgs[7] = "Your Growl message";
processArgs[8] = "-a";
processArgs[9] = "Adobe AIR Application Installer";
nativeProcessStartupInfo.arguments = processArgs;
nativeProcessStartupInfo.executable = file;

In this case, I’m also adding a bunch of arguments in my NativeProcessStartupInfo object. These arguments will be passed on to the growlnotify command-line tool. In this example, I’m setting up the name of my application, the notification priority, the title and message of my notification and I’m also telling it to use the icon associated with the Adobe AIR Application Installer. (Check out the Growlnotify docs for more info on these settings)

Next and last step is to actually call the native script.

process = new NativeProcess();
process.start(nativeProcessStartupInfo);

This code above will result in this Growl notification:

The only downside of using native scripts is that you’ll have to package your application specifically for the operating system you wrote your native script for. So in this case, I’d have to package it as a .DMG file since Growl only exists on OS X. That said, I really wouldn’t mind an OS X version of TweetDeck that allows me to use Growl instead of their custom notifications…

I really can’t wait to see what you guys are going to build with AIR 2! You can already start today! Check out Adobe Labs for more information!

Read full storyComments { 50 }

The HTML5 Flash Marriage: Geolocation source

Last Friday I blogged about how HTML5 and Flash could also just work together. A few people have asked if they could get the source files. I just packaged and uploaded the FLA, ActionScript class and HTML files. Download the zip file here.

A few people have also noted that the demo doesn’t work across different platforms even when using the same browser. While I wanted to demonstrate how Flash and HTML5 can coexist and even complement each other, it is (sadly) also a demonstration on how HTML5 is being implemented differently across browsers and operating systems. Feel free to post a comment if you know about fixes or workarounds in the JavaScript to make it work on more browsers.

Read full storyComments { 4 }

The HTML5 Flash Marriage: Geolocation

I probably don’t need to tell you that there’s a lot of buzz (and fuzz) about how HTML5 is going to kill Flash. You probably know how I feel about this… I think the web is big enough for both of them… Even better… I think they could potentially complement each other!

Geolocation is a good example. HTML5 is going to get a geolocation API that works just beautifully even on devices with no GPS. Flash based applications will (currently) only get access to geolocation APIs when targeting the AIR runtime on mobile. Some browsers (I only know of Firefox 3.5 on Mac and the WebKit browser on the Nexus One) already support the HTML5 geolocation API… So why not use that to get geo information into your Flash based application?

It’s actually extremely easy to do…

But first a little bit of background as to why I was looking for this functionality. I’m actually building “this demo app” that needs the geolocation in order to have the functionality I was looking for. I want this app to work in as many places as possible. With the Flash Platform I can build this for my browser and my desktop. For the Apple phone I can export it as a native app and for the Nexus One I can use the device browser with Flash Player 10.1.

Now… How does it work? The HTML5 geolocation API is extremely easy to use and, like I said earlier, you don’t even need to have a GPS enabled device.

function getGEO()
{
	// First check if your browser supports the geolocation API
	if (navigator.geolocation)
	{
		alert("HTML 5 is getting your location");
		// Get the current position
		navigator.geolocation.getCurrentPosition(function(position)
		{
			lat = position.coords.latitude
			long = position.coords.longitude;
			// Pass the coordinates to Flash
			passGEOToSWF(lat, long);
		});
	} else {
		alert("Sorry... your browser does not support the HTML5 GeoLocation API");
	}
}
function passGEOToSWF(lat,long)
{
	alert("HTML 5 is sending your location to Flash");
	// Pass the coordinates to mySWF using ExternalInterface
	document.getElementById("mySWF").passGEOToSWF(lat,long);
}

In my Flash application, I’m using ExternalInterface so I can communicate between JavaScript and my SWF. When my Google Maps component is ready, I call the GetGEO JavaScript method:

ExternalInterface.call("getGEO");

When the JavaScript method gets a result from the geolocation API, it will pass it on to the passGEOToSWF method. In my Flash application, I just listen for that method call and then call the code to update the map.

ExternalInterface.addCallback("passGEOToSWF", onPassGEOToSWF);

If you don’t have an HTML5 ready browser, check out this video of the application running in Firefox 3.6. Even cooler is that this also works in the browser on my Flash Player 10.1 enabled Nexus One (Please note that the network is slower on the N1 and thus it isn’t able to keep up with loading new map images. This has nothing to do with Flash Player 10.1 or the application.):

If you have Firefox 3.5 or newer installed, you can give it a try yourself: http://www.webkitchen.be/geolocation. I’m sure there are other browsers out there that also already have the geolocation API but this is the only one I tested on the Mac.

Hopefully this gives you a good idea of how HTML5 and Flash can also just work together (instead of killing each other ;-)). Flash on!

UPDATE: While writing this blog post, @robertbak pinged me on Twitter saying that he wrote a library to use in your Flex applications. Check it out on the Flex Exchange.

UPDATE: For the source files check out this blogpost.

Read full storyComments { 39 }

Flash Player 10.1 and battery life on mobile devices

It’s great to see all the excitement about Flash Player 10.1 coming to mobile devices! Though some people need to learn to get their facts straight before jumping to conclusions.

One of the biggest improvements in Flash Player 10.1 is the memory and CPU consumption which obviously also has a big impact on the battery life. Battery life on mobile devices is very important and thus always top of mind for the engineering team!

There was a lot of commotion around the video that my colleague Michael Chaize published. He showcased a number of Flash based apps to show off the performance of FP10.1. Some of the applications he showed are CPU intensive and thus also potential battery drainers.

Mark Doherty posted a great follow up post with some background information on how we test battery consumption and performance internally. He also recorded a 17 minute YouTube video which resulted in a 6% battery drain. That results to being able to watch over 4 hours worth of YouTube video over WiFi using Flash Player. I can’t even do that on my brand new MacBook Pro (which is supposed to be able to give me 8 hours of battery life)… I’m not even sure I can do that on my Apple phone using their native YouTube app…

Today, Michael posted a follow up video where he plays a 26 minute video and plays a Flash based game for 12 minutes.

He noted a 10% battery drain after the playing the video which calculates down to 4.3 hours of video. Playing the Flash based game for 12 minutes resulted in a 4% drain which boils down to 5 hours of continuous gaming in the browser using Flash Player 10.1.

Those numbers are pretty impressive to me! Especially when you consider that this is still a pre-release version of the Flash Player running on a pre-release version of Android.

Kudos to the Flash Player team! Flash on!

Read full storyComments { 6 }

Video tutorial: Create Flex container components with Flash CS4

In this video I show you how to make a Flex container component with Flash CS4 and the Flex Component Kit for Flash.

The Flex Component Kit for Flash is incredibly powerful and allows you to combine your Flash design/development skills with the power of the Flex framework.

Subscribe to the Adobe Developer Connection videos on iTunes.

Read full storyComments { 9 }

Video tutorial: Add video to your Flex application

In this video I show you how to add a simple video player to your Flex application by using nothing but standard Flex components.

Read full storyComments { 6 }