Most windows applications be needed to center on screen both vertically and horizontally, for AIR applications, we can use window.runtime.flash. system.Capabilities to do it. This class provides properties that describe the system and runtime that are hosting HTML content. We can provide appropriate content to as many users as possible by using the Capabilities. We can use code to alter its presentation when we know the conputer’s capabilities.

Use screen resolution and native window size properties to set desired coordinates, we can center our AIR application window.

hecock-s-open-air-window

Set AIR window x coordinate using Capabilities.screenResolutionX and nativeWindow.width. Do the same for y coordinate with Capabilities.screenResolutionY and nativeWindow.height.

The following is sample source code.

  1. < ?xml version="1.0" encoding="utf-8"?>
  2. <mx :WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
  3.     width="450" height="400" layout="absolute"
  4.     creationComplete="creationCompleteHandler(event);">
  5.  
  6.     </mx><mx :Script>
  7.         < ![CDATA[
  8.             private function creationCompleteHandler(event: Event): void
  9.             {
  10.                 nativeWindow.x = (Capabilities.screenResolutionX - nativeWindow.width) / 2;
  11.                 nativeWindow.y = (Capabilities.screenResolutionY - nativeWindow.height) / 2;
  12.             }
  13.         ]]>
  14.     </mx>

The code is simple but hope it will be helpful for someone.

Related Posts