Creating NativeWindows in AIR and displaying Flex content in them
Thanks to Daniel Dura for event getting me on the right path to making this work!
In AIR, you can create new popup windows buy using the NativeWindow object. This gives you the ability to do something like a fullscreen projector from your application. The concept rocks, but in beta right now, it’s not fully implemented and there are some hacks you have to do to get your content to show up in the new NativeWindow.
When I first started trying to load my custom component, I couldn’t see a thing even after using Daniel’s suggestion of adding it to the main application’s display list. It seems that percentage values were being ignored and the size of the canvas being added was being set to 0x0 because of it. That made it invisible obviously.
So, I figured maybe if we wrapped it in another container, set that containers width/height, maybe that would light things up. That *did* help, but I was still tracing out the window size and it was showing up at 400×200, which was wrong since I’d called maximize() on the window. Naturally, I’m thinking there’s an event to let us know when it’s fullscreen, and there is of course:
You have to wait for that to fire, so you can get the correct window size. You use that to set the size of your container canvas, and then the children’s percentage settings work as you’d expect. At this point, I added my custom component (SlideShowViewer) to the container, but NOT to the NativeWindow’s stage just yet.
Now, adding it to the main application’s display list will initialize the component to work correctly (be careful not to add it to the main applications stage, use application.addChild())
Daniel had added it first to a hiddenCanvas on stage, but I didnt’ want something just sitting around for this purpose and this works just fine.
Finally, add container to the NativeWindow’s stage and all should be good.
In the constructor:
[as]public function SlideShowWindow(initOptions:NativeWindowInitOptions)
[as]protected function handleDisplayChange(e:NativeWindowDisplayStateEvent):void
container.width = width;
container.height = height;
slideShowViewer = new SlideShowViewer();
//trace(“DISPLAY CHANGE”, this.width, this.height, slideShowViewer.width, slideShowViewer.height);