Holy hell. I’ve been tearing my hair out all night trying to figure out how to make a fully transparent and chrome-less native window using the mx:Window class. Luckily, thanks to Bradical from this post, I found the solution. You just need to set showFlexChrome equal to False in your mx:Window component. So quick mini-tutorial for anyone doing custom chrome/transparent native windows:
If you’re looking at a lot of AIR documentation you’ll probably see references to a NativeWindow class and think that’s what you want to use to create a new native window. If you’re doing Flex work however, you won’t be able to add any components from the Flex Framework to that NativeWindow because NativeWindow is a Flash class and doesn’t include the Flex (mx) libraries. So what you’ll want to do instead is create a custom component that extends mx:Window:
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" width="200" height="75" styleName="chromeless" layout="absolute" verticalAlign="middle" horizontalAlign="center"> <mx:Style> .chromeless { showFlexChrome: false; background-image: ""; background-color: ""; padding: 0px; } </mx:Style> <mx:Image source="@Embed('assets/notifier.png')" id="background" /> <mx:Label id="lbl" color="#ffffff" fontSize="20" textAlign="center" top="25" bottom="25" right="0" left="0" /> </mx:Window> |
Notice I set up a style called chromeless, knocked out the background image/color and set the padding to zero like any other custom chrome application, but I’ve also set the showFlexChrome property to false. Now you’re good to go and you can start using all of the Flex Framework in your native window. In this case I’m setting the other native window chrome properties when I actually create the window (in my main Application file):
public function createNewWindow() : void { var win : NotificationWindow = new NotificationWindow(); win.systemChrome = NativeWindowSystemChrome.NONE; win.type = NativeWindowType.LIGHTWEIGHT; win.transparent = true; win.open(true); } |
NotificationWindow is just the name of my MXML component (NotifyWindow.mxml) and I can set the system chrome options in that file directly, or on creation like I did above. If you’re going to be using the same chrome settings for your custom native window class, it’s probably easiest just to set the system chrome options inside your component.
Hope that helps other folks, and a huge thanks to Bradical, wherever you are!
Tweet