Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center / AIR Quick Starts for ActionScript developers /

Interacting with a window

by Joe Ward

Joe Ward

by Christian Cantrell

Christian Cantrell
  • blogs.adobe.com/cantrell

Modified

9 June 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Adobe AIR Flash Professional

Requirements

Prerequisite knowledge

General experience of building applications with Flash Professional is suggested. For more details on getting started with this Quick Start, refer to Building the Quick Start sample applications with Flash.

User level

Intermediate

Required products

  • Adobe AIR
  • Flash Professional (Download trial)

Sample files

  • PixelPerfect.zip
  • PixelPerfect.air

The PixelPerfect sample application, shown in Figure 1, performs basic tasks on window objects. These tasks include creating, resizing, moving, and closing windows.

PixelPerfect application
Figure 1. The PixelPerfect sample application enables you to perform basic tasks on window objects.

The PixelPerfect application demonstrates how you can use the AIR window API to:

  • Open multiple windows
  • Obtain a reference to a window
  • Use mouse events to trigger operations on a window
  • Use the startResize() method of the NativeWindow class to resize a window
  • Use the constants of the NativeWindowResize class to specify how a window resize operation is completed
  • Use the startMove() method of the NativeWindow class to move a window
  • Use the close() method of the NativeWindow class to close a window
  • Use full screen mode

Note: This is a sample application provided, as is, for instructional purposes.

Understanding the code

PixelPerfect presents a simple user interface that lets users access the NativeWindow API to modify application windows based on user input. PixelPerfect supports the following user interactions:

  • Context menu: Right-click the window to open a menu of window commands.
  • Drag corners or sides to resize: The mouseDown event triggers application logic to run that calculates the mouse position and, if appropriate, makes a call to the NativeWindow.startResize() method.
  • Drag the middle to move: The mouseDown event triggers application logic that calculates the mouse position and, if appropriate, makes a call to the NativeWindow.startMove() method.
  • Arrow keys move one pixel at a time: The keyDown event triggers application logic that detects if an arrow key was pressed. If it was, the NativeWindow.x or NativeWindow.y property is either increased or decreased by 1, depending on whether the arrow that was pressed was the Down arrow key, the Up arrow key, the Left arrow key, or the Right arrow key. This process occurs each time the user presses an arrow key.
  • Shift + arrow keys resize one pixel at a time: The keyDown event triggers application logic that detects if the Shift key was pressed in combination with an arrow key. If such a key combination was pressed, the NativeWindow.width or Window.height property is either increased or decreased by 1, depending on whether the arrow that was pressed was the Down arrow key, the Up arrow key, the Left arrow key, or the Right arrow key. This process occurs each time the user presses the Shift key in combination with an arrow key.
  • Mouse wheel changes opacity: The event listener that was created to detect activity from the mouse wheel makes a call to an event handler that determines the extent and direction in which the mouse wheel is turned. These values are used to modify the alpha property, which affects the level of transparency that is applied to the background color.
  • Double-click to quit: The doubleClick event triggers application logic that makes an explicit call to the Window.close() method.
  • Press Ctrl+N to create a window: The keyDown event triggers application logic that detects if the Ctrl+N keys was pressed. If so, a new instance of the Ruler class (which extends NativeWindow ) is created, displaying a new ruler window.

Creating a Window

To create a window, PixelPerfect instantiates a new Ruler object. The Ruler class extends the NativeWindow class. In the Ruler constructor, the NativeWindowInitOptions object is created and passed to the NativeWindow super class constructor:

public function Ruler(width:uint = 300, height:uint = 300, x:uint = 50, y:uint = 50, alpha:Number = .4) { var winArgs:NativeWindowInitOptions = new NativeWindowInitOptions(); winArgs.systemChrome = NativeWindowSystemChrome.NONE; winArgs.transparent = true; super(winArgs); //...

The rest of the constructor initializes the properties of the new window and its members.

Resizing the application window

The startResize() method receives a constant value defined by the NativeWindowResize class that indicates the edge or corner of the window from which the user is dragging the window to resize it. The startResize() method triggers a system-controlled resizing of the window.

The application also explicitly sets the window bounds in response to keyboard events. In this case, no resize events are involved. The following code snippet sets the window bounds inside a switch statement:

switch (e.keyCode) { case Keyboard.DOWN: if (e.shiftKey) height += 1; else y += 1; drawTicks(bounds); break; case Keyboard.UP: if (e.shiftKey) height -= 1; else y -= 1; drawTicks(bounds); break; case Keyboard.RIGHT: if (e.shiftKey) width += 1; else x += 1; drawTicks(bounds); break; case Keyboard.LEFT: if (e.shiftKey) width -= 1; else x -= 1; drawTicks(bounds); break; case 78: createNewRuler(); break; }

This code snippet also shows the key events used to move the window and to create new windows.

Moving the application window

The startMove() method is used to begin a system-controlled move of the window. The PixelPerfect sample application uses this method when the mouse device controls the move.

When the arrow keys control the parameters of the move, PixelPerfect changes the window bounds, one pixel at a time, by incrementing or decrementing the x or y property of the window. (The code is included in the switch statement in the preceding code snippet.)

Changing the transparency of the application window

The visible background of the window is a Sprite object that was added to the ruler stage. The application changes the transparency of the background by adjusting the alpha property of the background sprite in response to mouse wheel events:

private function onMouseWheel(e:MouseEvent):void { var delta:int = (e.delta < 0) ? -1 : 1; if (sprite.alpha >= .1 || e.delta > 0) sprite.alpha += (delta / 50); }

For a window to be transparent against the desktop, the window must be created with transparency enabled by setting transparent property to true in the NativeWindowsInitOptions object passed to the window constructor. The transparency state of a window cannot be changed once the window is created.

Closing the application window

When a doubleclick event is dispatched, PixelPerfect calls the close() method of the window.

private function onDoubleClick(e:Event):void { close(); }

A close event is dispatched after the window is closed, signaling the completion of the close process. After a window is closed, it cannot be reopened. Closing the window frees the resources associated with the window (unless they are referenced elsewhere) so that they can be garbage collected. However, the initial window created by AIR is never garbage collected. The application is responsible for closing its windows so that the associated resources can be freed. When the last window of an application is closed, the application also exits. This default behavior can be changed by setting the Shell object autoExit property to false.

For more information about the methods and properties of the AIR windowing API, see the ActionScript 3 Reference for the Flash Platform.

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement