Hi, I'm Brian Reavis. I design and develop
awesome things for COLOURlovers. I love mountains.

A few libraries (as3nativealertlib and AirAlert) claim to provide native alert dialogs to Flex/AIR—but each one emulates the UI, which isn’t quite ideal.

A workaround is to use the HTMLLoader class to get totally-native modal alerts laid out by the OS. This works by leveraging Flex/AIR’s integration of Webkit into the runtime. Calling the alert method of the window triggers an alert just as a web browser would.

var htmlInterface:HTMLLoader;
function alert(message:String):void {
   if (!htmlInterface) {
      htmlInterface = new HTMLLoader();
      htmlInterface.loadString('<html><head></head><body></body></html>');
   }
   try { htmlInterface.window.alert(message); }
   catch (e:Error) {}
}

Not exactly the cleanest of solutions… but it works! The only downside is the inability to set the title of the dialog.

Copyright © 2012 – Brian Reavis. All rights reserved. The views expressed here are my own and do not necessarily reflect the views of COLOURlovers / Creative Market.