Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Window Operations

In this section we look into controlling a Window’s dimensions, positioning and behaviors.

Resizing a Window

You can invoke a resize action on a window by calling the following method:

NativeWindow.startResize();

The next code example (as shown in Listing 5.4) demonstrates an mx.core.Window being created with a button that initiates the resize of that same window from the lower-right corner. (Click and hold the Start Resize button and drag your mouse to resize the window.)

Listing 5.4. Initiating Window Resize

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
   xmlns:mx="http://www.adobe.com/2006/mxml"
   layout="vertical"
   verticalAlign="middle"
   horizontalAlign="center">

   <mx:Script>
      <![CDATA[
      import mx.controls.Button;
      import mx.core.Window;
      private var myWindow:Window;

      private function openWindow():void
      {
                var dragButton:Button = new Button();
         dragButton.label = "Click, hold and drag mouse";
         dragButton.addEventListener( MouseEvent.MOUSE_DOWN, resizeWindow );

         myWindow = new Window();         myWindow.width = 300;
         myWindow.systemChrome = NativeWindowSystemChrome.STANDARD;
         myWindow.type = NativeWindowType.NORMAL;
         myWindow.setStyle( "horizontalAlign", "center" );
         myWindow.setStyle( "verticalAlign", "middle" );
         myWindow.addChild( dragButton );
         myWindow.open( true );
      }
      private function resizeWindow( event:MouseEvent ):void
      {
         myWindow.nativeWindow.startResize( NativeWindowResize.BOTTOM_RIGHT );
      }
      ]]>
   </mx:Script>
   <mx:Button label="Create Window" click="openWindow()" />
</mx:WindowedApplication>

Listing 5.4 is an oversimplified example for sake of clarity. A more realistic use case would involve having graphic elements within a custom window chrome initiate this resize behavior. (See “Creating Custom Window Chrome” later in this chapter.)

Moving a Window

To move a window, call the startMove() method on the NativeWindow instance. If you’re using mx.core.Window, reference the underlying NativeWindow via the nativeWindow property:

var myWindow:Window = new Window();
myWindow.open();
myWindow.nativeWindow.startMove();

Maximizing, Minimizing, and Restoring a Window

Maximizing causes a window to expand to the bounds of the current screen. To maximize a window, use

NativeWindow.maximize();

To minimize a window, use

NativeWindow.minimize();

To restore a window, use

NativeWindow.restore();

Restoring a window simply means that the window will return to the size that it was before it was either minimized or maximized.

Closing a Window

To close a window, use

NativeWindow.close()

Closing a window empties the contents of the window, but if any other objects have references to that content, the content objects are not destroyed. You can check the closed property of a window to test whether a window has been closed. If the window being closed is the last one, and the NativeApplication.autoExit property is set to true (the default setting), the application quits.

  • + Share This
  • 🔖 Save To Your Account