Chromeless AIR application

| 2 min read

I had to get an AIR application without the OS window, let's say windowless or chromeless.

I needed to be able, with my own graphics, to minimize, restore, maximize, close, close in the system tray or dock, fullscreen and resize.

You can find several tutorials on Internet (with which I got inspired) but I put all these functionalities in one small example as it is convenient.

You need to set 2 parameters out of the code, in the XML description file:

<systemChrome>none</systemChrome>
<transparent>true</transparent>

I won’t explain the code, I guess it is easy enough to find out. You can comment if something is not clear for you.

Here is the code of the main mxml file:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" showFlexChrome="false" creationComplete="init()">

<mx:Script>
<![CDATA[

[Embed(source="assets/iconDock.png")]
[Bindable]
public var IconDock:Class;

private function init():void {
registerMovementHandler();
setDock();
}

public function registerMovementHandler():void {
appCanvas.addEventListener(MouseEvent.MOUSE_DOWN, mouseDrag);
btResizeBottomRight.addEventListener(MouseEvent.MOUSE_DOWN, resizeWindow);
btResizeBottomLeft.addEventListener(MouseEvent.MOUSE_DOWN, resizeWindow);
btResizeTopRight.addEventListener(MouseEvent.MOUSE_DOWN, resizeWindow);
btResizeTopLeft.addEventListener(MouseEvent.MOUSE_DOWN, resizeWindow);
}

public function mouseDrag(e:MouseEvent):void {
if (e.target == e.currentTarget) stage.nativeWindow.startMove();
}

public function resizeWindow(e:MouseEvent = null):void {
if (e.target == e.currentTarget) {
var corner:String;
switch(e.currentTarget){
case btResizeBottomRight:
corner = NativeWindowResize.BOTTOM_RIGHT;
break;
case btResizeBottomLeft:
corner = NativeWindowResize.BOTTOM_LEFT;
break;
case btResizeTopRight:
corner = NativeWindowResize.TOP_RIGHT;
break;
case btResizeTopLeft:
corner = NativeWindowResize.TOP_LEFT;
break;
}
stage.nativeWindow.startResize(corner);
}
}

public function setDock():void {
if (NativeApplication.supportsSystemTrayIcon){
dockProperties();
SystemTrayIcon(NativeApplication.nativeApplication.icon).menu = dockMenu();
}
}

private function dockProperties():void{
SystemTrayIcon(NativeApplication.nativeApplication.icon).tooltip = "Soundstep | chromeless window";
SystemTrayIcon(NativeApplication.nativeApplication.icon).addEventListener(MouseEvent.CLICK, undock);
}

private function dockMenu():NativeMenu {
var menu:NativeMenu = new NativeMenu();
var open:NativeMenuItem = new NativeMenuItem("Open");
var close:NativeMenuItem = new NativeMenuItem("Close");
open.addEventListener(Event.SELECT, undock);
close.addEventListener(Event.SELECT, closeWindow);
menu.addItem(open);
menu.addItem(new NativeMenuItem("",true));
menu.addItem(close);
return menu;
}

public function dock():void {
stage.nativeWindow.visible = false;
NativeApplication.nativeApplication.icon.bitmaps = [new IconDock() as Bitmap];
}

public function undock(evt:Event):void {
stage.nativeWindow.visible = true;
stage.nativeWindow.orderToFront();
NativeApplication.nativeApplication.icon.bitmaps = [];
}

public function closeWindow(e:Event = null):void {
stage.nativeWindow.close();
}

public function setFullscreen():void {
var state:String = (stage.displayState == StageDisplayState.FULL_SCREEN) ? StageDisplayState.NORMAL : StageDisplayState.FULL_SCREEN;
stage.displayState = state;
}

]]>

</mx:Script>

<mx:Canvas right="0" left="0" top="0" bottom="0" backgroundColor="#CF3232" id="appCanvas">

<mx:Label buttonMode="true" mouseChildren="false" text="Min" top="10" color="#000000" id="btMin" click="minimize()" horizontalCenter="58"/>
<mx:Label buttonMode="true" mouseChildren="false" text="Max" top="10" color="#000000" id="btMax" click="maximize()" horizontalCenter="-45"/>
<mx:Label buttonMode="true" mouseChildren="false" text="Close" top="10" color="#000000" id="btClose" click="closeWindow()" horizontalCenter="96"/>
<mx:Label buttonMode="true" mouseChildren="false" text="Restore" color="#000000" id="btRestore" click="restore()" top="10" horizontalCenter="-91"/>
<mx:Label buttonMode="true" mouseChildren="false" y="10" text="Tray/Dock" color="#000000" id="btSys" click="dock()" horizontalCenter="8"/>
<mx:Label buttonMode="true" mouseChildren="false" text="Fullscreen" color="#000000" horizontalCenter="0" bottom="10" id="btFullscreen" click="setFullscreen()"/>

<mx:Canvas width="20" height="20" backgroundColor="#7B0707" borderStyle="none" borderColor="#FFFFFF" id="btResizeBottomRight" themeColor="#494949" right="0" bottom="0" />

<mx:Canvas width="20" height="20" backgroundColor="#7B0707" borderStyle="none" borderColor="#FFFFFF" id="btResizeTopLeft" themeColor="#494949" left="0" top="0" />

<mx:Canvas width="20" height="20" backgroundColor="#7B0707" borderStyle="none" borderColor="#FFFFFF" id="btResizeBottomLeft" themeColor="#494949" bottom="0" left="0" />

<mx:Canvas width="20" height="20" backgroundColor="#7B0707" borderStyle="none" borderColor="#FFFFFF" id="btResizeTopRight" themeColor="#494949" right="0" top="0" />

</mx:Canvas>

</mx:WindowedApplication>

You can [download the source](http://www.soundstep.com/blog/experiments/chromeless/chromeless.zip) or install the AIR application:

In order to view this page
You must enable Javascript
And download the Flash Player
[![get flash player](images/get_flashplayer.gif)](http://www.adobe.com/products/flashplayer/)

<script src="/blog/experiments/js/swfobject.js" type="text/javascript"></script>

<script type="text/javascript">// <!-- // <![CDATA[ var so = new SWFObject('/blog/experiments/badge.swf', 'chromeless', '217', '180', '9', '#FFFFFF'); so.addParam('FlashVars', 'appname=Chromeless&#038;appurl=http://www.soundstep.com/blog/experiments/chromeless/Chromeless.air&#038;airversion=1.0.1&#038;imageurl=/blog/experiments/badge.jpg'); so.write('chromeless'); // ]]> // --></script>