How do I make an AIR Window be always on top?

This question comes in from Martijn:


hi, thanks for posting that stuff about minimizing the adobe air window :) I wondered if you also know if air supports the native window to be "always on top" on your desktop. I can't find anything about the subject. Thanks, Martijn

I've done some experiments with this in the past, but couldn't find my old code. The WindowsApplication tag has an alwaysInFront property.

To make an app always stay on top, just do this:


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" alwaysInFront="true">
</mx:WindowedApplication>

In my experiments, I was testing out AIR to run in Kiosk mode application, so I was also using alwaysInFront with a full screen. You can make things full screen by doing this:


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" alwaysInFront="true"
applicationComplete="onApplicationComplete()">

<mx:Script><![CDATA[
            
public function onApplicationComplete():void{
this.stage.displayState = StageDisplayState.FULL_SCREEN;
}
]]>
</mx:Script>
</mx:WindowedApplication>

Using the ApplicationComplete event, I trigger a function to run this in "large" mode. It just sets the displayState of the stage into Full Screen. You cannot run this code on CreationComplete because the Application stage object is not initialized before the ApplicationComplete event is triggered.

Did I mention I love answering questions? You should feel free to ask away.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
EZEKIEL's Gravatar CAN YOU HELP ON HOW TO DO THIS IN FLASH CS3 FOR AIR APPLICATION
# Posted By EZEKIEL | 2/6/09 11:59 AM
Jeffry Houser's Gravatar EZEKIEL,

I can't help w/ Flash CS3, sorry.
# Posted By Jeffry Houser | 2/16/09 8:31 AM
Harkonenn's Gravatar @Ezekiel - Check this out:

http://www.adobe.com/devnet/air/flash/quickstart/c...

In Flash CS3/CS4 (AS3) you can add this to your code:

stage.nativeWindow.alwaysInFront = true;
# Posted By Harkonenn | 6/1/09 3:33 PM
Jeffry Houser's Gravatar Harkonenn,

Thanks for the knowledge.
# Posted By Jeffry Houser | 6/1/09 3:46 PM
EZEKIEL's Gravatar @Harkonenn;
You are wonderful, Thank You so much.
# Posted By EZEKIEL | 7/31/09 3:39 PM
OmarOmar's Gravatar If you run for exmaple any game - the "always on top" window will hide... Any soulutions for this?
# Posted By OmarOmar | 4/20/10 6:41 PM
frager's Gravatar thanks, but when I copy this code to the flash it show me erros.
I want to make always on top in a adobe air, as2.
# Posted By frager | 6/7/10 7:16 AM
Jeffry Houser's Gravatar Frager,

Are you using AIR with Flex, or Flash, or HTML / Dreamweaver, or something else altogether?

This code is Flex based. I have no idea how you would do it with ActionScript 2--does anyone still use AS2?
# Posted By Jeffry Houser | 6/7/10 10:48 AM
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.