Packageorg.wiiflash
Classpublic final class Wiimote
Implementsflash.events.IEventDispatcher

The Wiimote class represents a Wiimote. A Wiimote object has to be connected to the WiiFlash server. The WiiFlash server gathers available information from a Wiimote through Bluetooth and sends it back.

It is important to remember the following information regarding the motion sensors:

Multiple Wiimotes can be handled as well. It is possible to create up to four Wiimote objects. If more than four Wiimote objects have been created an error will be thrown. After one Wiimote object made a successful connection to the WiiFlash Server all the other Wiimote objects will fire the connect event immediately.


Example
This example shows how to create a Wiimote and connect it to the Basic WiiFlash server:
  
  var wiimote:Wiimote = new Wiimote();
  wiimote.addEventListener( Event.CONNECT, onWiimoteConnect );
  wiimote.connect();
  
This example shows how to listen for events from the A button:
  
  wiimote.addEventListener( ButtonEvent.A_PRESS, onWiimoteAPress );
  wiimote.addEventListener( ButtonEvent.A_RELEASE, onWiimoteARelease );
  

See also

Wiimote description on wiili.org


Public Properties
 PropertyDefined by
  a : Boolean
[read-only] Indicates if button A is pressed.
Wiimote
  b : Boolean
[read-only] Indicates if button B is pressed.
Wiimote
  balanceBoard : BalanceBoard
[read-only] The Balance Board that is attached to this Wiimote object.
Wiimote
  batteryLevel : Number
[read-only] Wiimote battery level from 0 to 1 (full batteries).
Wiimote
  classicController : ClassicController
[read-only] The ClassicController that is attached to this Wiimote object.
Wiimote
  connected : Boolean
[read-only] Indicates whether this Wiimote object is currently connected to the WiiFlash server.
Wiimote
  down : Boolean
[read-only] Indicates if button Down is pressed.
Wiimote
  hasBalanceBoard : Boolean
[read-only] Indicates if a Balance Board is attached to this Wiimote object.
Wiimote
  hasClassicController : Boolean
[read-only] Indicates if a Classic Controller is attached to this Wiimote object.
Wiimote
  hasNunchuk : Boolean
[read-only] Indicates if a Nunchuk is attached to this Wiimote object.
Wiimote
  home : Boolean
[read-only] Indicates if button Home is pressed.
Wiimote
  id : uint
[read-only] Indicates Wiimote ID, for multiple wiimotes handling
Wiimote
  ir : IR
[read-only] The IR data that this Wiimote object recieves.
Wiimote
  leds : int
Bitmask of the Wiimote's LEDs.
Wiimote
  left : Boolean
[read-only] Indicates if button Left is pressed.
Wiimote
  minus : Boolean
[read-only] Indicates if button - is pressed.
Wiimote
  mouseControl : Boolean
Flag of the Wiimote's mouse control.
Wiimote
  nunchuk : Nunchuk
[read-only] The Nunchuk that is attached to this Wiimote object.
Wiimote
  one : Boolean
[read-only] Indicates if button 1 is pressed.
Wiimote
  pitch : Number
[read-only] Pitch angle of the Wiimote in radians.
Wiimote
  plus : Boolean
[read-only] Indicates if button + is pressed.
Wiimote
  right : Boolean
[read-only] Indicates if button Right is pressed.
Wiimote
  roll : Number
[read-only] Roll angle of the Wiimote in radians.
Wiimote
  rumble : Boolean
Flag of the Wiimote's rumble state.
Wiimote
  rumbleTimeout : uint
Flag for a rumble that stops after given amount of milliseconds.
Wiimote
  sensorX : Number
[read-only] Value of the x acceleration sensor.
Wiimote
  sensorY : Number
[read-only] Value of the y acceleration sensor.
Wiimote
  sensorZ : Number
[read-only] Value of the z acceleration sensor.
Wiimote
  two : Boolean
[read-only] Indicates if button 2 is pressed.
Wiimote
  up : Boolean
[read-only] Indicates if button Up is pressed.
Wiimote
  yaw : Number
[read-only] Yaw angle of the Wiimote in radians.
Wiimote
Public Methods
 MethodDefined by
  
Creates a new Wiimote object.
Wiimote
  
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with a Wiimote object so that the listener receives notification of an event.
Wiimote
  
close():void
Closes the connection between this Wiimote object and the WiiFlash server.
Wiimote
  
connect(host:String = "127.0.0.1", port:int = 0x4a54):void
Connects the Wiimote to the specified host and port.
Wiimote
  
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow.
Wiimote
  
hasEventListener(type:String):Boolean
Checks whether the Wiimote object has any listeners registered for a specific type of event.
Wiimote
  
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the Wiimote object.
Wiimote
  
toString():String
Returns the string representation of the specified object.
Wiimote
  
update(pack:ByteArray):void
Wiimote
  
willTrigger(type:String):Boolean
Checks whether an event listener is registered with this Wiimote object or any of its ancestors for the specified event type.
Wiimote
Events
 EventSummaryDefined by
   Dispatched when button A has been pressed.Wiimote
   Dispatched when button A has been released.Wiimote
   Dispatched when the Balance Board has been connected to Wiimote.Wiimote
   Dispatched when the Classic Controller has been disconnected from Wiimote.Wiimote
   Dispatched when button B has been pressed.Wiimote
   Dispatched when button B has been released.Wiimote
   Dispatched when the Classic Controller has been connected to Wiimote.Wiimote
   Dispatched when the Classic Controller has been disconnected from Wiimote.Wiimote
   Dispatched when a Wiimote object has successfully connected to the WiiFlash server.Wiimote
   Dispatched when Nunchuk button C has been pressed.Wiimote
   Dispatched when Nunchuk button C has been released.Wiimote
   Dispatched when button Down has been pressed.Wiimote
   Dispatched when button Down has been released.Wiimote
   Dispatched when button Home has been pressed.Wiimote
   Dispatched when button Home has been released.Wiimote
   Dispatched when a Wiimote object could not establish a connection.Wiimote
   Dispatched when Point 1 of the IR sensor bar has been found.Wiimote
   Dispatched when Point 1 of the IR sensor bar has been lost.Wiimote
   Dispatched when Point 2 of the IR sensor bar has been found.Wiimote
   Dispatched when Point 2 of the IR sensor bar has been lost.Wiimote
   Dispatched when button Left has been pressed.Wiimote
   Dispatched when button Left has been released.Wiimote
   Dispatched when button - has been pressed.Wiimote
   Dispatched when button - has been released.Wiimote
   Dispatched when Nunchuk has been connected to Wiimote.Wiimote
   Dispatched when Nunchuk has been disconnected from Wiimote.Wiimote
   Dispatched when button 1 has been pressed.Wiimote
   Dispatched when button 1 has been released.Wiimote
   Dispatched when button + has been pressed.Wiimote
   Dispatched when button + has been released.Wiimote
   Dispatched when button Right has been pressed.Wiimote
   Dispatched when button Right has been released.Wiimote
   Dispatched when button 2 has been pressed.Wiimote
   Dispatched when button 2 has been released.Wiimote
   Dispatched when Wiimote data has been updated.Wiimote
   Dispatched when button Up has been pressed.Wiimote
   Dispatched when button Up has been released.Wiimote
   Dispatched when Nunchuk button Z has been pressed.Wiimote
   Dispatched when Nunchuk button Z has been released.Wiimote
Public Constants
 ConstantDefined by
  LED1 : int = 1
[static] The first LED.
Wiimote
  LED2 : int = 2
[static] The second LED.
Wiimote
  LED3 : int = 4
[static] The third LED.
Wiimote
  LED4 : int = 8
[static] The fourth LED.
Wiimote
Property detail
aproperty
a:Boolean  [read-only]

Indicates if button A is pressed.

Implementation
    public function get a():Boolean
bproperty 
b:Boolean  [read-only]

Indicates if button B is pressed.

Implementation
    public function get b():Boolean
balanceBoardproperty 
balanceBoard:BalanceBoard  [read-only]

The Balance Board that is attached to this Wiimote object.

Implementation
    public function get balanceBoard():BalanceBoard
batteryLevelproperty 
batteryLevel:Number  [read-only]

Wiimote battery level from 0 to 1 (full batteries).

Implementation
    public function get batteryLevel():Number

Example
This example shows how to retrieve the battery level :
var battery:Number = wiimote.batteryLevel;

classicControllerproperty 
classicController:ClassicController  [read-only]

The ClassicController that is attached to this Wiimote object.

Implementation
    public function get classicController():ClassicController
connectedproperty 
connected:Boolean  [read-only]

Indicates whether this Wiimote object is currently connected to the WiiFlash server.

Implementation
    public function get connected():Boolean
downproperty 
down:Boolean  [read-only]

Indicates if button Down is pressed.

Implementation
    public function get down():Boolean
hasBalanceBoardproperty 
hasBalanceBoard:Boolean  [read-only]

Indicates if a Balance Board is attached to this Wiimote object.

Implementation
    public function get hasBalanceBoard():Boolean
hasClassicControllerproperty 
hasClassicController:Boolean  [read-only]

Indicates if a Classic Controller is attached to this Wiimote object.

Implementation
    public function get hasClassicController():Boolean
hasNunchukproperty 
hasNunchuk:Boolean  [read-only]

Indicates if a Nunchuk is attached to this Wiimote object.

Implementation
    public function get hasNunchuk():Boolean
homeproperty 
home:Boolean  [read-only]

Indicates if button Home is pressed.

Implementation
    public function get home():Boolean
idproperty 
id:uint  [read-only]

Indicates Wiimote ID, for multiple wiimotes handling

Implementation
    public function get id():uint
irproperty 
ir:IR  [read-only]

The IR data that this Wiimote object recieves.

Implementation
    public function get ir():IR
ledsproperty 
leds:int  [read-write]

Bitmask of the Wiimote's LEDs.

Implementation
    public function get leds():int
    public function set leds(value:int):void

Example
This example shows how to turn the left and right LED on:
wiimote.leds = Wiimote.LED1 | Wiimote.LED4;

leftproperty 
left:Boolean  [read-only]

Indicates if button Left is pressed.

Implementation
    public function get left():Boolean
minusproperty 
minus:Boolean  [read-only]

Indicates if button - is pressed.

Implementation
    public function get minus():Boolean
mouseControlproperty 
mouseControl:Boolean  [read-write]

Flag of the Wiimote's mouse control.

Implementation
    public function get mouseControl():Boolean
    public function set mouseControl(value:Boolean):void

Example
This example shows how to enable the mouse control feature:
wiimote.mouseControl = true;
This example shows how to disable the mouse control feature:
wiimote.mouseControl = false;

nunchukproperty 
nunchuk:Nunchuk  [read-only]

The Nunchuk that is attached to this Wiimote object.

Implementation
    public function get nunchuk():Nunchuk
oneproperty 
one:Boolean  [read-only]

Indicates if button 1 is pressed.

Implementation
    public function get one():Boolean
pitchproperty 
pitch:Number  [read-only]

Pitch angle of the Wiimote in radians. This value is scaled by the calibration data that has been read from the Wiimote.

Implementation
    public function get pitch():Number
plusproperty 
plus:Boolean  [read-only]

Indicates if button + is pressed.

Implementation
    public function get plus():Boolean
rightproperty 
right:Boolean  [read-only]

Indicates if button Right is pressed.

Implementation
    public function get right():Boolean
rollproperty 
roll:Number  [read-only]

Roll angle of the Wiimote in radians. This value is scaled by the calibration data that has been read from the Wiimote.

Implementation
    public function get roll():Number
rumbleproperty 
rumble:Boolean  [read-write]

Flag of the Wiimote's rumble state.

Implementation
    public function get rumble():Boolean
    public function set rumble(value:Boolean):void

Example
This example shows how to enable the rumble feature:
wiimote.rumble = true;
This example shows how to disable the rumble feature:
wiimote.rumble = false;

rumbleTimeoutproperty 
rumbleTimeout:uint  [read-write]

Flag for a rumble that stops after given amount of milliseconds.

Implementation
    public function get rumbleTimeout():uint
    public function set rumbleTimeout(value:uint):void

Example
This example shows how to enable the rumble feature for one second:
wiimote.rumbleTimeout = 1000;

sensorXproperty 
sensorX:Number  [read-only]

Value of the x acceleration sensor. This value is scaled by the calibration data that has been read from the Wiimote.

Implementation
    public function get sensorX():Number
sensorYproperty 
sensorY:Number  [read-only]

Value of the y acceleration sensor. This value is scaled by the calibration data that has been read from the Wiimote.

Implementation
    public function get sensorY():Number
sensorZproperty 
sensorZ:Number  [read-only]

Value of the z acceleration sensor. This value is scaled by the calibration data that has been read from the Wiimote.

Implementation
    public function get sensorZ():Number
twoproperty 
two:Boolean  [read-only]

Indicates if button 2 is pressed.

Implementation
    public function get two():Boolean
upproperty 
up:Boolean  [read-only]

Indicates if button Up is pressed.

Implementation
    public function get up():Boolean
yawproperty 
yaw:Number  [read-only]

Yaw angle of the Wiimote in radians. This value is scaled by the calibration data that has been read from the Wiimote.

A sensor measures only acceleration. The default acceleration a sensor can measure is the gravity vector that is pointing downwards. This has no affect to the yaw angle and is the reason whil there wont be much changes in value. Using an IR sensor bar can solve this issue.

Implementation
    public function get yaw():Number
Constructor detail
Wiimote()constructor
public function Wiimote()

Creates a new Wiimote object.


Throws
— Thrown if more than four Wiimote objects have been created.
Method detail
addEventListener()method
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void

Registers an event listener object with a Wiimote object so that the listener receives notification of an event.

Parameters
type:String — The type of event.
 
listener:Function — The listener function that processes the event.
 
useCapture:Boolean (default = false) — Determines whether the listener works in the capture phase or the target and bubbling phases.
 
priority:int (default = 0) — The priority level of the event listener.
 
useWeakReference:Boolean (default = false) — Determines whether the reference to the listener is strong or weak.

See also

close()method 
public function close():void

Closes the connection between this Wiimote object and the WiiFlash server.

connect()method 
public function connect(host:String = "127.0.0.1", port:int = 0x4a54):void

Connects the Wiimote to the specified host and port.

Parameters
host:String (default = "127.0.0.1") — The name of the host to connect to.
 
port:int (default = 0x4a54) — The port number to connect to.

See also

dispatchEvent()method 
public function dispatchEvent(event:Event):Boolean

Dispatches an event into the event flow.

Parameters
event:Event — The Event object dispatched into the event flow.

Returns
Boolean

See also

hasEventListener()method 
public function hasEventListener(type:String):Boolean

Checks whether the Wiimote object has any listeners registered for a specific type of event.

Parameters
type:String — The type of event.

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

See also

removeEventListener()method 
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void

Removes a listener from the Wiimote object.

Parameters
type:String — The type of event.
 
listener:Function — The listener object to remove.
 
useCapture:Boolean (default = false) — Specifies whether the listener was registered for the capture phase or the target and bubbling phases.

See also

toString()method 
public function toString():String

Returns the string representation of the specified object.

Returns
String — A string representation of the object.
update()method 
public function update(pack:ByteArray):voidParameters
pack:ByteArray
willTrigger()method 
public function willTrigger(type:String):Boolean

Checks whether an event listener is registered with this Wiimote object or any of its ancestors for the specified event type.

Parameters
type:String — The type of event.

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

See also

Event detail
aPressevent 
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button A has been pressed.

aReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button A has been released.

balanceBoardConnectevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when the Balance Board has been connected to Wiimote.

balanceBoardDisconnectevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when the Classic Controller has been disconnected from Wiimote.

bPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button B has been pressed.

bReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button B has been released.

classicControllerConnectevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when the Classic Controller has been connected to Wiimote.

classicControllerDisconnectevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when the Classic Controller has been disconnected from Wiimote.

connectevent  
Event object type: flash.events.Event

Dispatched when a Wiimote object has successfully connected to the WiiFlash server.

cPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when Nunchuk button C has been pressed.

cReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when Nunchuk button C has been released.

downPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Down has been pressed.

downReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Down has been released.

homePressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Home has been pressed.

homeReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Home has been released.

ioErrorevent  
Event object type: flash.events.IOErrorEvent

Dispatched when a Wiimote object could not establish a connection.

ir1Foundevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when Point 1 of the IR sensor bar has been found.

ir1Lostevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when Point 1 of the IR sensor bar has been lost.

ir2Foundevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when Point 2 of the IR sensor bar has been found.

ir2Lostevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when Point 2 of the IR sensor bar has been lost.

leftPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Left has been pressed.

leftReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Left has been released.

minusPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button - has been pressed.

minusReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button - has been released.

nunchukConnectevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when Nunchuk has been connected to Wiimote.

nunchukDisconnectevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when Nunchuk has been disconnected from Wiimote.

onePressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button 1 has been pressed.

oneReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button 1 has been released.

plusPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button + has been pressed.

plusReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button + has been released.

rightPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Right has been pressed.

rightReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Right has been released.

twoPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button 2 has been pressed.

twoReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button 2 has been released.

updateevent  
Event object type: org.wiiflash.events.WiimoteEvent

Dispatched when Wiimote data has been updated.

upPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Up has been pressed.

upReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when button Up has been released.

zPressevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when Nunchuk button Z has been pressed.

zReleaseevent  
Event object type: org.wiiflash.events.ButtonEvent

Dispatched when Nunchuk button Z has been released.

Constant detail
LED1constant
public static const LED1:int = 1

The first LED.

LED2constant 
public static const LED2:int = 2

The second LED.

LED3constant 
public static const LED3:int = 4

The third LED.

LED4constant 
public static const LED4:int = 8

The fourth LED.