Adobe
製品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
その他の製品一覧
ソリューション
デジタルマーケティング
デジタルメディア
教育
金融機関
Web Experience Management
その他のソリューション
ラーニング サポート ダウンロード 会社情報
ご購入
アドビストア 安心のサポート& サービス
アカデミックストア 学生、教職員、個人向け
アドビライセンスストア 中小企業向け
ボリュームライセンスについて 企業、教育機関、官公庁向け
販売パートナー
キャンペーン情報
検索
 
情報 サインイン
ようこそ、 さん カート 注文状況 マイアカウント
マイアカウント
注文状況
アカウント情報の変更
コミュニケーションの設定を変更
サインアウト
サインインの目的 お客様のアカウントや体験版ダウンロード、製品の拡張機能、コミュニティエリアへのアクセスなどを管理するため
Adobe
製品 セクション ご購入   検索  
ソリューション 会社情報
サポート ラーニング
サインイン サインアウト 注文状況 マイアカウント
先行予約の提供開始予定日Date. 商品が発送されるまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。 先行予約の提供開始予定日Date. ダウンロードの準備が整うまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。
個数:
ご購入には学生・教職員個人版の購入資格の確認が必要です。
小計
カートの中身を見る
Adobe Developer Connection / Adobe AIR Developer Center / AIR Quick Starts for ActionScript developers /

Interacting with a window

by Joe Ward

Joe Ward

著者 Christian Cantrell

Christian Cantrell
  • blogs.adobe.com/cantrell

Modified

9 June 2010

ページ ツール

Facebookでシェア
Twitterでツイート
LinkedInでシェア
ブックマーク
印刷

タグ

必要条件

この記事に必要な予備知識

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.

ユーザーレベル

中級

必要な製品

  • Adobe AIR
  • Flash Professional (Download trial)

サンプルファイル

  • PixelPerfect.zip (26 KB)
  • PixelPerfect.air (83 KB)

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.

製品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • モバイルアプリ
  • Photoshop
  • Touch Apps

ソリューション

  • デジタルマーケティング
  • コンテンツオーサリング
  • Web Experience Management

業種別ソリューション

  • 教育
  • 金融機関

サポート

  • ヘルプ&サポート
  • 注文と返品
  • ダウンロードに関するヘルプ
  • ユーザー登録に関するヘルプ

ラーニング

  • ADC: Adobe Developer Center
  • Adobe TV
  • Design Magazine
  • Photoshop Magazine
  • Focus In

ご購入方法

  • アドビストア
  • アカデミックストア
  • アドビライセンスストア
  • ボリュームライセンスについて
  • 販売パートナー
  • キャンペーン情報

ダウンロード

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

会社情報

  • プレスルーム
  • パートナープログラム
  • 企業の社会的責任(英語)
  • 採用情報
  • 投資家の皆様へ(英語)
  • イベント&セミナー
  • Legal(英語)
  • セキュリティ
  • お問い合わせ
国・地域および言語の選択 日本(変更)
国・地域および言語の選択 閉じる

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.

利用条件 | プライバシーポリシーとCookie (更新)

Reviewed by TRUSTe: site privacy statement