The NativeWindow class provides an interface for creating and controlling native desktop windows.

You can test for support at run time on desktop devices using the NativeWindow.isSupported property.

OpenFL target support: This feature is supported on all desktop operating systems, but is not supported on mobile operating systems, including iOS and Android.

Adobe AIR profile support: This feature is supported on all desktop operating systems, but is not supported on mobile devices or AIR for TV devices. See AIR Profile Support for more information regarding API support across multiple profiles.

A reference to the NativeWindow instance is returned by the window constructor. A reference to a NativeWindow instance can also be accessed using the stage.nativeWindow property of any display object on that window's stage:

var window:NativeWindow = displayObject.stage.nativeWindow;

The properties of a NativeWindow instance can only be accessed by application content. If non-application content attempts to access the NativeWindow object, a security error will be thrown.

Content can be added to a window using the DisplayObjectContainer methods of the Stage object such as addChild().

The following operations on NativeWindow objects are asynchronous: close(), maximize(), minimize(), restore(), and bounds changes. An application can detect when these operations have completed by listening for the appropriate events.

If the NativeApplication.autoExit property is true, which is the default, the application will close when its last window is closed (and all close event handlers have returned). If autoExit is false, then NativeApplication.nativeApplication.exit() must be called to terminate the application.

NativeWindow objects will not be garbage collected after the window constructor has been called and before close() has been called. It is the responsibility of the application to close its own windows.

Static variables

staticread onlyisSupported:Bool

Indicates whether native windows are supported on the client system.

staticread onlysupportsMenu:Bool

Indicates whether OpenFL supports native window menus on the current computer system.

When NativeWindow.supportsMenu is true, a native menu will be displayed for a window when a NativeMenu object is assigned to the window menu property (unless the window systemChrome property is NativeWindowSystemChrome.NONE). Be sure to use the NativeWindow.supportsMenu property to determine whether the operating system supports native window menus. Using other means (such as Capabilities.os) to determine support can lead to programming errors (if some possible target operating systems are not considered).

Note: Assigning a menu to a window when NativeWindow.supportsMenu is false or when the window systemChrome property is NativeWindowSystemChrome.NONE is allowed, but does nothing.

staticread onlysupportsTransparency:Bool

Indicates whether OpenFL supports native windows with transparent pixels.

When NativeWindow.supportsTransparency is true, transparency in pixels of a native window will be honored, if the window transparent property is set to true. Opacity of all pixels will be set to 1 if NativeWindow.supportsTransparency is false, regardless of the value of the window transparent property. Fully transparent pixels will render as black when NativeWindow.supportsTransparency is false. Be sure to use the NativeWindow.supportsTransparency property to determine whether the operating system supports transparency. Using other means (such as Capabilities.os) to determine support can lead to programmin errors (if some possible target operating systems are not considered).

Note: The value of this property might change while an application is running, based on user preferences set for the operating system.

Constructor

new(initOptions:NativeWindowInitOptions)

Creates a new NativeWindow instance and a corresponding operating system window.

The settings defined in the initOptions parameter cannot be changed after the window is created. Invalid initOptions settings will cause an illegal operation error to be thrown. Settings that are valid but not available on the current system will not throw an exception. The window capabilities specific to the current operating system can be detected, if desired, using the static NativeWindow members such as systemMaxSize.

The default window size is determined by the operating system, and windows are created in an invisible state. To prevent changes to the window from being visible, do not change the window visible property to true or call activate() until the window changes are finished.

Variables

read onlyactive:Bool

Indicates whether this window is the active application window.

Use the activate() method to make a window active.

bounds:Rectangle

The size and location of this window.

The dimensions of a window include any system chrome. The dimensions of a window's stage are equal to the dimensions of the window, minus the size of any system chrome. Changing the width and height of the window will change the stage's stageWidth and stageHeight. The reverse also applies; changing the stage dimensions will change the window size.

A resize event is dispatched whenever the width or height of this window changes. Likewise, a move event is dispatched whenever the origin (x,y) of this window changes. On Mac OS and Windows, setting the bounds property directly will not dispatch a moving or resizing event. However, on Linux the NativeWindow does dispatch a moving and resizing events when you set the bounds property.

Setting the bounds property of a window is equivalent to setting its x, y, width, and height properties. Likewise, setting any of the individual dimensions is equivalent to setting the bounds property. When you set all the dimensions at the same time by using the bounds property, fewer events are dispatched.

The order in which the individual dimensions are set is not guaranteed. On Linux window managers that do not allow windows to extend off the desktop area, a change to an individual property may be blocked even though the net affect of applying all the property changes would have resulted in a legal window.

If the width or height specified is less than the minimum or greater than the maximum allowed width or height, then the window width or height is set to the closest legal size. The factors that determine the minimum and maximum width and height are the following:

  • The minSize and maxSize properties of the NativeWindow object
  • The minimum and maximum operating system limits, which are the values of NativeWindow.systemMinSize and NativeWindow.systemMaxSize.
  • The maximum width and height of a window in Adobe AIR, which are each 4095 pixels. (In AIR 1.5 and earlier, the maximum width and height of a window is 2880 pixels each.)
  • The minimum width and height required by any displayed system chrome.

Pixel values are rounded to the nearest integer when the position or dimensions of a window are changed.

read onlyclosed:Bool

Indicates whether this window has been closed.

Accessing the following properties on a closed window will throw an illegal operation error:

  • title
  • bounds
  • x, y, width, height
  • displayState
  • visible

Likewise, calling the following methods on a closed window will also throw an illegal operation error:

  • minimize()
  • maximize()
  • restore()
  • startResize()
  • startMove()

read onlydisplayState:NativeWindowDisplayState

The display state of this window.

height:Float

The height of this window in pixels.

The dimensions of a window include any system window chrome that is displayed. The height of the usable display area inside a window is available from the Stage.stageHeight property.

Changing the height property of a window is equivalent to changing the height through the bounds property.

If the height specified is less than the minimum or greater than the maximum allowed height, then the window height is set to the closest legal size. The factors that determine the minimum and maximum height are the following:

  • The minSize.y and maxSize.y properties of the NativeWindow object
  • The minimum and maximum operating system limits, which are the values of NativeWindow.systemMinSize.y and NativeWindow.systemMaxSize.y.
  • The maximum height of a window in Adobe AIR, which is 4095 pixels (2880 pixels in AIR 1.5 and earlier).

On Linux, setting the height property is an asynchronous operation.

To detect the completion of the height change, listen for the resize event, which is dispatched on all platforms.

Pixel values are rounded to the nearest integer when the height of a window is changed.

maxSize:Point

The maximum size for this window.

The size limit is specified as the coordinates of a Point object. The point x property corresponds to the window width, the y property to the window height.

The maxSize restriction is enforced for window resizing operation invoked both through Haxe code and through the operating system.

Setting maxSize will change the window bounds if the current bounds are larger than the new maximum size.

If the width or height specified is greater than the maximum allowed width or height, then the window width is set to the closest legal size. The factors that determine the minimum and maximum width and height are the following:

  • The maximum operating system limit, which is the value NativeWindow.systemMaxSize.
  • The maximum width and height of a window in Adobe AIR, which is 4095 pixels for each. (In AIR 1.5 and earlier, the maximum width and height of a window is 2880 pixels each.)

Note: On some operating systems, such as Mac OS X, maximizing a window will only enlarge the window to the maxSize value even if the maximized window will be smaller than the operating system screen. The window will still be in the maximized display state.

See also:

read onlymaximizable:Bool

Reports the maximizable setting used to create this window.

The maximizable setting cannot be changed after a window is created.

Note: Some Linux window managers allow windows to be maximized by the user even when the maximizable property is set to false.

minSize:Point

The minimum size for this window.

The size limit is specified as the coordinates of a Point object. The point x property corresponds to the window width, the y property to the window height.

Setting minSize, will change the window bounds if the current bounds are smaller than the new minimum size.

The minSize restriction is enforced for window resizing operations invoked both through ActionScript code and through the operating system.

Note: The width and height of any displayed system chrome may make it impossible to set a window as small as the specified minimum size.

See also:

read onlyminimizable:Bool

Reports the minimizable setting used to create this window.

The minimizable setting cannot be changed after a window is created.

Note: Some Linux window managers allow windows to be minimizable by the user even when the minimizable property is set to false.

read onlyowner:NativeWindow

The NativeWindow object that owns this window.

Window ownership is established when a window is created and cannot be changed. To create a window that has an owner, set the owning NativeWindow object as the owner property of the NativeWindowInitOptions object used to create the owned window.

Note: On Linux, some window managers do not display owned windows in front of the owning window when the owner is in fullscreen mode.

read onlyrenderMode:String

Reports the window renderMode setting used to create this window.

The value returned by NativeWindow.renderMode will be one of the constants defined in the NativeWindowRenderMode class.

The renderMode setting cannot be changed after a window is created.

read onlyresizable:Bool

Reports the resizable setting used to create this window.

The resizable setting cannot be changed after a window is created.

read onlystage:Stage

The Stage object for this window. The Stage object is the root object in the display list architecture used in OpenFL.

The stage is the root of the display list for the window. Add visual display objects to a window by adding them to the stage or to another object already in the display list of this stage. The stage dimensions are those of the window client area when the window uses system chrome. The stage dimensions are equal to the dimensions of the window if system chrome is not used.

read onlysystemChrome:NativeWindowSystemChrome

Reports the system chrome setting used to create this window.

The values returned by NativeWindow.systemChrome will be one of the constants defined in the NativeWindowSystemChrome class.

The system chrome setting cannot be changed after a window is created.

title:String

The window title.

The title will appear in the system chrome for the window, if displayed, as well as in other system-dependent locations (such as the task bar).

read onlytransparent:Bool

Reports the transparency setting used to create this window.

The transparent property cannot be changed after a window is created Transparency affects both the visual appearance and the mouse behavior of the window. On Windows and Mac OS X, the window will not capture mouse events when the alpha value of the pixel is below a certain threshold, which varies between about .06 and .01 depending on th operating system. On Linux, the window will capture mouse events above completely transparent areas and therefore will prevent users from accessing other windows and items on the desktop.

Note: Window transparency cannot always be supported. If the user's operating system configuration is such that transparency is not available, the window will be created without transparency. Areas that would have been transparent are composited against black. Use the NativeWindow.supportsTransparency property to determine whether window transparency is supported.

visible:Bool

Specifies whether this window is visible.

An invisible window is not displayed on the desktop, but all window properties and methods are valid.

By default, visible is set to false. To display a window, set visible to true or call NativeWindow.activate().

If this window has an owner, the visible state of that owning window determines whether this window is displayed. If the owning window is not displayed, then any owned windows are not displayed, even if their visible properties are true.

Note: On Mac OS X, setting visible to false on a minimized window will not remove the window icon from the dock. If a user subsequently clicks the dock icon, the window will return to the visible state and be displayed on the desktop.

width:Float

The width of this window in pixels.

The dimensions reported for a native window include any system window chrome that is displayed. The width of the usable display area inside a window is available from the Stage.stageWidth property.

Changing the width property of a window is equivalent to changing the width through the bounds property.

If the width specified is less than the minimum or greater than the maximum allowed width, then the window width is set to the closest legal size. The factors that determine the minimum and maximum width are the following:

  • The minSize.x and maxSize.x properties of the NativeWindow object
  • The minimum and maximum operating system limits, which are the values of NativeWindow.systemMinSize.x and NativeWindow.systemMaxSize.x.
  • The maximum width of a window in Adobe AIR, which is 4095 pixels (2880 pixels in AIR 1.5 and earlier).

On Linux, setting the width property is an asynchronous operation.

To detect the completion of the width change, listen for the resize event, which is dispatched on all platforms.

Pixel values are rounded to the nearest integer when the width of a window is changed.

x:Float

The horizontal axis coordinate of this window's top left corner relative to the origin of the operating system desktop.

On systems with more than one monitor, x can be negative. If you save the value, perhaps to reposition a window at its previous location, you should always verify that the window is placed in a usable location when the position is restored. Changes in screen resolution or monitor arrangement can can result in a window being placed off screen. Use the Screen class to obtain information about the desktop geometry.

Changing the x property of a window is equivalent to changing the location through the bounds property.

On Linux, setting the x property is an asynchronous operation.

To detect the completion of the position change, listen for the move event, which is dispatched on all platforms.

Pixel values are rounded to the nearest integer when the x-coordinate of a window is changed.

y:Float

The vertical axis coordinate of this window's top left corner relative to the upper left corner of the operating system's desktop.

On systems with more than one monitor, y can be negative. If you save the value, perhaps to reposition a window at its previous location, you should always verify that the window is placed in a usable location when the position is restored. Changes in screen resolution or monitor arrangement can can result in a window being placed off screen. Use the Screen class to obtain information about the desktop geometry.

Changing the y property of a window is equivalent to changing the location through the bounds property.

On Linux, setting the y property is an asynchronous operation.

To detect the completion of the position change, listen for the move event, which is dispatched on all platforms.

Pixel values are rounded to the nearest integer when the y-coordinate of a window is changed.

Methods

activate():Void

Activates this window.

Activating a window will:

  • Make the window visible
  • Bring the window to the front
  • Give the window keyboard and mouse focus

On Linux, activate() is an asynchronous operation.

The NativeWindow object dispatches an activate event on all platforms.

close():Void

Closes this window.

A close event is dispatched as soon as the close operation is complete. A closing event will not be dispatched. If cancellation of the close operation should be allowed, manually dispatch a closing event and check whether any registered listeners cancel the default behavior before calling the close() method.

When a window is closed, any windows that it owns are also closed. The owned windows do not dispatch closing events.

If display object instances that are currently in the window are not referenced elsewhere they will be garbage collected and destroyed, except on the initial application window created by AIR. To allow display objects on the initial window to be garbage collected, remove them from the window stage.

After being closed, the NativeWindow object is still a valid reference, but accessing most properties and methods will throw an illegal operation error.

Closed windows cannot be reopened. If the window is already closed, no action is taken and no events are dispatched.

Note: to hide a window without closing it, set the window's visible property to false.

listOwnedWindows():Vector<NativeWindow>

Returns a list of the NativeWindow objects that are owned by this window.

You cannot change ownership of NativeWindows by adding or removing objects from the returned vector. Window ownership cannot be changed after a window is created.

maximize():Void

Maximizes this window.

Calling maximize() method dispatches a displayStateChange event, and, if applicable, a move and a resize event. Whereas system chrome will dispatch a displayStateChanging event that can be canceled when a maximize command is initiated by a user, your maximize logic must manually implement this behavior, if desired.

The maximize() method executes asynchronously. To detect the completion of the state change, listen for the displayStateChange event. If the window is already maximized, no action is taken and no events are dispatched.

OS behavior notes:

  • On operating systems, such as Mac OS X, in which maximizing a window does not also prevent resizing, calling maximize() will zoom the window to fill the screen, but will not prevent subsequent resizing of the window. Resizing a zoomed window will also restore the display state.
  • On some operating systems, such as Mac OS X, as well as on some Linux window managers, maximizing a window will not expand the window beyond the width and height specified in the maxSize property. On others, the window will expand to fill the screen even if the screen is larger than the maxSize.
  • Some Linux window managers do not allow utility windows to be maximized.

minimize():Void

Minimizes this window.

Calling minimize() dispatches a displayStateChange event, and, if applicable, a move and a resize event. Whereas system chrome will dispatch a displayStateChanging event that can be canceled when a minimize command is initiated by a user, calling minimize() directly does not. Your minimize logic may manually implement this behavior, if desired.

The minimize() method executes asynchronously. To detect th completion of the state change, listen for the displayStateChange event, which is dispatched on all platforms. If the window is already minimized, no action is taken and no events are dispatched.

Any windows owned by this window are hidden when it is minimized. The owned windows do not dispatch displayStateChanging or displayStateChange events.

Notes:

  • On Windows, minimizing an invisible window (visible == false), will make the window visible.
  • Some Linux window managers do not allow utility windows to be minimized.

restore():Void

Restores this window from either a minimized or a maximized state.

Calling restore() dispatches a displayStateChange event, and, if applicable, a move and a resize event. Whereas system chrome will dispatch a displayStateChanging event that can be canceled when a restore command is initiated by a user, your restore logic must manually implement this behavior, if desired.

If the window is already in the NativeWindowDisplayState.NORMAL state, no action is taken and no events are dispatched.

To detect the completion of the state change, listen for the displayStateChange event, which is dispatched on all platforms.

Inherited Variables

Inherited Methods

Defined by EventDispatcher

@:value({ useWeakReference : false, priority : 0, useCapture : false })addEventListener<T>(type:EventType<T>, listener:T ‑> Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void

Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. You can register event listeners on all nodes in the display list for a specific type of event, phase, and priority.

After you successfully register an event listener, you cannot change its priority through additional calls to addEventListener(). To change a listener's priority, you must first call removeListener(). Then you can register the listener again with the new priority level.

Keep in mind that after the listener is registered, subsequent calls to addEventListener() with a different type or useCapture value result in the creation of a separate listener registration. For example, if you first register a listener with useCapture set to true, it listens only during the capture phase. If you call addEventListener() again using the same listener object, but with useCapture set to false, you have two separate listeners: one that listens during the capture phase and another that listens during the target and bubbling phases.

You cannot register an event listener for only the target phase or the bubbling phase. Those phases are coupled during registration because bubbling applies only to the ancestors of the target node.

If you no longer need an event listener, remove it by calling removeEventListener(), or memory problems could result. Event listeners are not automatically removed from memory because the garbage collector does not remove the listener as long as the dispatching object exists(unless the useWeakReference parameter is set to true).

Copying an EventDispatcher instance does not copy the event listeners attached to it.(If your newly created node needs an event listener, you must attach the listener after creating the node.) However, if you move an EventDispatcher instance, the event listeners attached to it move along with it.

If the event listener is being registered on a node while an event is being processed on this node, the event listener is not triggered during the current phase but can be triggered during a later phase in the event flow, such as the bubbling phase.

If an event listener is removed from a node while an event is being processed on the node, it is still triggered by the current actions. After it is removed, the event listener is never invoked again(unless registered again for future processing).

Parameters:

type

The type of event.

useCapture

Determines whether the listener works in the capture phase or the target and bubbling phases. If useCapture is set to true, the listener processes the event only during the capture phase and not in the target or bubbling phase. If useCapture is false, the listener processes the event only during the target or bubbling phase. To listen for the event in all three phases, call addEventListener twice, once with useCapture set to true, then again with useCapture set to false.

priority

The priority level of the event listener. The priority is designated by a signed 32-bit integer. The higher the number, the higher the priority. All listeners with priority n are processed before listeners of priority n-1. If two or more listeners share the same priority, they are processed in the order in which they were added. The default priority is 0.

useWeakReference

Determines whether the reference to the listener is strong or weak. A strong reference(the default) prevents your listener from being garbage-collected. A weak reference does not.

Class-level member functions are not subject to garbage collection, so you can set useWeakReference to true for class-level member functions without subjecting them to garbage collection. If you set useWeakReference to true for a listener that is a nested inner function, the function will be garbage-collected and no longer persistent. If you create references to the inner function(save it in another variable) then it is not garbage-collected and stays persistent.

Weak references are supported on some OpenFL targets only, including html5, cpp, and flash/air. On other targets, this parameter is ignored, and the reference will be strong instead.

Throws:

ArgumentError

The listener specified is not a function.

dispatchEvent(event:Event):Bool

Dispatches an event into the event flow. The event target is the EventDispatcher object upon which the dispatchEvent() method is called.

Parameters:

event

The Event object that is dispatched into the event flow. If the event is being redispatched, a clone of the event is created automatically. After an event is dispatched, its target property cannot be changed, so you must create a new copy of the event for redispatching to work.

Returns:

A value of true if the event was successfully dispatched. A value of false indicates failure or that preventDefault() was called on the event.

Throws:

Error

The event dispatch recursion limit has been reached.

hasEventListener(type:String):Bool

Checks whether the EventDispatcher object has any listeners registered for a specific type of event. This allows you to determine where an EventDispatcher object has altered handling of an event type in the event flow hierarchy. To determine whether a specific event type actually triggers an event listener, use willTrigger().

The difference between hasEventListener() and willTrigger() is that hasEventListener() examines only the object to which it belongs, whereas willTrigger() examines the entire event flow for the event specified by the type parameter.

When hasEventListener() is called from a LoaderInfo object, only the listeners that the caller can access are considered.

Parameters:

type

The type of event.

Returns:

A value of true if a listener of the specified type is registered; false otherwise.

@:value({ useCapture : false })removeEventListener<T>(type:EventType<T>, listener:T ‑> Void, useCapture:Bool = false):Void

Removes a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect.

Parameters:

type

The type of event.

useCapture

Specifies whether the listener was registered for the capture phase or the target and bubbling phases. If the listener was registered for both the capture phase and the target and bubbling phases, two calls to removeEventListener() are required to remove both, one call with useCapture() set to true, and another call with useCapture() set to false.

toString():String

willTrigger(type:String):Bool

Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. This method returns true if an event listener is triggered during any phase of the event flow when an event of the specified type is dispatched to this EventDispatcher object or any of its descendants.

The difference between the hasEventListener() and the willTrigger() methods is that hasEventListener() examines only the object to which it belongs, whereas the willTrigger() method examines the entire event flow for the event specified by the type parameter.

When willTrigger() is called from a LoaderInfo object, only the listeners that the caller can access are considered.

Parameters:

type

The type of event.

Returns:

A value of true if a listener of the specified type will be triggered; false otherwise.