Package | flash.ui |
Class | public final class GameInput |
Inheritance | GameInput EventDispatcher Object |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
GameInput
class is the entry point into the GameInput
API. You can use this API to manage the communications between an
application and game input devices (for example: joysticks, gamepads, and wands).
AIR profile support: This feature is supported only on AIR for TV devices. See AIR Profile Support for more information regarding API support across multiple profiles.
The main purpose of this class is to provide access to the supported
input devices that are connected to your application platform. This
static class enumerates the connected input devices in a list. You
access a device from the list using the getDeviceAt(index:int)
method.
The numDevices
property provides the number of input
devices currently connected to your platform. Use this value to
determine the upper bound of the list of devices.
Use an instance of this class to listen for events that notify you about the addition and removal of input devices. To listen these events, do the following:
-
Create an instance of the
GameInput
class. -
Add event listeners for the
GameInputEvent.DEVICE_ADDED
andGameInputEvent.DEVICE_REMOVED
events. (Events can only be registered on an instance of the class.)
This class also features the isSupported
flag, which
indicates whether the GameInput API is supported on your platform.
How to Detect One Game Input Device From Among Identical Devices
A common requirement for two-or-more player games is detecting one device from among identical devices. For example, applications sometimes must determine which device represents "Player 1", "Player 2", ..., "Player N".
Solution:
-
Add event listeners to every control on all undetected input devices. These event
listeners listen for
Event.CHANGE
events, which are dispatched whenever a control value changes. - The first time any control is activated (for example a button press or trigger pull) the application labels that device.
- Remove all of the event listeners from the remaining undetected input devices.
- Repeat steps 1-3 as required to identify the rest of the undetected input devices.
Related API Elements
flash.ui.GameInputControl
flash.ui.GameInputControlType
flash.ui.GameInputHand
flash.ui.GameInputFinger
flash.events.GameInputEvent
Property | Defined By | ||
---|---|---|---|
constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | ||
isSupported : Boolean [static] [read-only]
Indicates whether your platform supports the GameInput API. | GameInput | ||
numDevices : int [static] [read-only]
Provides the number of connected and registered input devices. | GameInput | ||
prototype : Object [static]
A reference to the prototype object of a class or function object. | Object |
Method | Defined By | ||
---|---|---|---|
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | ||
Dispatches an event into the event flow. | EventDispatcher | ||
[static]
Gets the input device at the specified index location in the list
of connected input devices. | GameInput | ||
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Removes a listener from the EventDispatcher object. | EventDispatcher | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Returns the primitive value of the specified object. | Object | ||
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Event | Summary | Defined By | ||
---|---|---|---|---|
[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher | |||
[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher | |||
Dispatched when a game input device is connected to your platform, or when an already connected device is switched on. | GameInput | |||
Dispatched when a game input device is removed from your platform, or when a connected device is switched off. | GameInput |
isSupported | property |
numDevices | property |
numDevices:int
[read-only] Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Provides the number of connected and registered input devices. (It is
possible for a device to be connected but not yet registered.) When
a device is connected and registered, the
GameInputEvent.DEVICE_ADDED
event is fired.
Implementation
public static function get numDevices():int
getDeviceAt | () | method |
public static function getDeviceAt(index:int):GameInputDevice
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 3 |
Gets the input device at the specified index location in the list of connected input devices.
The order of devices in the index may change whenever
a device is added or removed. You can check the name
and
id
properties on a GameInputDevice
object to
match a specific input device.
Parameters
index:int — The index position in the list of input devices.
|
GameInputDevice — The specified GameInputDevice .
|
Throws
RangeError — When the provided index is less than zero or
greater than (numDevices - 1) .
|
GameInputEvent.DEVICE_ADDED | Event |
flash.events.GameInputEvent
Dispatched when a game input device is connected to your platform, or when an already connected device is switched on.
GameInputEvent.DEVICE_REMOVED | Event |
flash.events.GameInputEvent
Dispatched when a game input device is removed from your platform, or when a connected device is switched off.
Mon Nov 28 2011, 06:48 AM -08:00