Real Text-To-Speech For Your Flash Apps

Text-to-speech has been around for many years, but you know it has never really worked properly. It sounded like a metal can, had issues with different languages, and so on. But I have good news for you.
Acapela created a SaaS (software as a service) offering for Text-To-Speech, which finally sounds pretty cool and I [...]

Introducing: Package Assistant (AIR 2 package utility built with AIR 2)

Two of the most requested features for AIR were the ability to create native installers and to launch/talk to native applications. Among other new features, AIR 2 allows you to do that. To build these native installers you have to use the command line compiler.
A while back I was thinking if it would be possible [...]

New AIR 1.5.2 API Examples and Features

Despite the ‘.2′ naming this is a pretty cool release for Adobe AIR developers and there are a few important new APIs that I think you’ll find very useful as well as a big change that should make every developer’s life a lot easier.

Getting Set Up
The first thing you need to do is download the new SDK and replace the old AIR 1.5 or 1.5.1 SDK. It’s pretty easy and it just consists of dropping the new AIR SDK folder into your Flex SDK (back it up first). The ditto command on the Mac works beautifully. You also need to make sure to change the namespace in your appname-app.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="">

Catching the “ESC” Key in Full Screen Mode
Now you’re ready to go. One oft-requested feature for AIR (and Flash Player) is the ability to capture the “escape” key and not have it exit full screen mode. With AIR 1.5.2 this is easy. You set an event handler for the keyDown event and then inside of the event handler you call event.preventDefault(). Here’s a quick example:

<?xml version="1.0" encoding="utf-8"?>
protected function btn_fullScreen_clickHandler(event:MouseEvent):void
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
btn_fullScreen.label = "Try pushing escape!"
protected function windowedapplication1_keyDownHandler(event:KeyboardEvent):void
if( event.keyCode == Keyboard.ESCAPE )
btn_fullScreen.label = "Nope, escape won't work. Try pushing the Enter Key";
if( event.keyCode == Keyboard.ENTER )
stage.displayState = StageDisplayState.NORMAL;
btn_fullScreen.label = "Go Full Screen!";
<s:Button id="btn_fullScreen" label="Go Full Screen!" click="btn_fullScreen_clickHandler(event)" />

Once you call the event.preventDefault() method you can use the Escape keyCode like any other key.

Garbage Collection of XML Data
Another one that will be huge for performance optimization is the ability to mark an XML object for immediate garbage collection. To do this you can use the new System.disposeXML(xml:XML) method. Oliver Goldman gave me a great explanation of what’s happening.

Even then, the disposeXML() call doesn’t immediately dispose of the XML. The XML object is backed by a graph of objects with parent/child pointers between them. Those pointers make it difficult for the GC to collect all of those objects. The disposeXML() call traverses the graph, setting all of those pointers to null, and making it much easier for collection to occur. The objects still aren’t collected right away, however—that’s still pending on the GC activity.

To use the new API you just have to call the method and then null out your XML variable. That will make it easier for the garbage collector to clean up. In the example below I load in a big XML file, do some parsing to it so that it loads into memory, then call the System.disposeXML() method.

public var xml:XML;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
var file:File = File.applicationDirectory.resolvePath("assets/Untitled.gpx");
var stream:FileStream = new FileStream();,FileMode.READ);
var str:String = stream.readUTFBytes(file.size);
xml = new XML(str);
protected function btn_loadXML_clickHandler(event:MouseEvent):void
var xmlList:XMLList = xml.children();
var text:XMLList = xml.text();
var xmlStr:String = xml.toString();
protected function btn_disposeXML_clickHandler(event:MouseEvent):void
System.disposeXML( xml );
xml = null;
Memory Profiler using the disposeXML() method

Memory Profiler using the disposeXML() method

You can see how this behaves in the profiler screenshot above. If you want to immediately garbage collect you can call System.gc() but if you use this often it can have negative performance implications (thanks to Ethan for the tip).

The last one I wanted to touch on was a new, friendlier install screen as blogged about by Joseph Labrecque and Oliver Goldman. We got rid of the “System Access: Unrestricted” for signed applications so that if you sign your app your end users will have a nicer install experience.

Adobe AIR 1.5.2 Signed App Install Screen

Adobe AIR 1.5.2 Signed App Install Screen

Those are three of the biggies. You can download the sample project here if you want to run the full screen example and the System.disposeXML() example.