Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

70 | Chapter 4: AIR Mini-Cookbook


Anative window initially has no content outside of the run-
time. Unlike the JavaScript window.open( ) method, an
application cannot simply specify a URL for the content to
be displayed. The window is so raw that an application must
first add anHTMLControlto the window, size it, and tell it
what content to load. TheHTMLControlconstructor takes no
arguments, exposes properties for width and height, and
exposes anHTMLControl.load( )method which can be used to
load external content:


var control = new window.runtime.flash.html.HTMLControl( );
var page =
air.File.applicationResourceDirectory.resolve( "login.html" );

control.width = login.stage.stageWidth;
control.height = login.stage.stageHeight;
control.load( new air.URLRequest( page.url ) );

TheNativeWindow.stage property represents a Stage object
and is used to determine the viewable area for sizing the
HTMLControl. Using NativeWindow.width or NativeWindow.
heightfor theHTMLControlsizing would have resulted in an
HTMLControlas large as the window itself (including chrome).
Stage.stageWidthandStage.stageHeightwill size the con-
trol to fit the viewable area.


The Stage is also where controls will get added for display
(called the display list), and is responsible for how the con-
tent inside of it will be positioned and sized. For most applica-
tions this means settingStage.scaleModetoStageScaleMode.
NO_SCALEandStage.aligntoStageAlign.TOP_LEFT. Calling
Stage.addChild( )will add theHTMLControlto the viewable
area. Using this approach, it is possible to have multiple
HTMLControl controls in one single window:


win.stage.scaleMode = window.runtime.flash.display.
StageScaleMode.NO_SCALE;
win.stage.align = window.runtime.flash.display.StageAlign.
TOP_LEFT;
win.stage.addChild( control );
Free download pdf