Class com.wiicade.Nunchuk

Description

This class provides information about one of the Nunchuck attachment controllers. This class cannot be instantiated directly and should only be obtained through the WiiRemote.getAttachment() function.

Button states can be to polled to determine whether a given button is pressed or not. To determine this information, call the isDown() function with one of the following Nunchuk constants:

Constant
BUTTON_C
BUTTON_Z


The following is an example of how you would check if the Z button is pressed on the Nintendo Wii Remote:

if(Wii.getRemote(1).getAttachment().isDown(Nunchuk.BUTTON_Z)) { ...do logic... }

Please note that support for the Nunchuk controller is severely limited at this time. Only information from controllers 1, 2, and 3 can be obtained. Controller 0 does not currently return any information about the controller. For the controllers that are supported, only the button presses are available. No stick position or motion sensing data is available.

Field Index

BUTTON_C, BUTTON_Z

Method Index

addEventListener(), getStickX(), getStickY(), isDown(), removeEventListener()

Field Detail

BUTTON_C

static public BUTTON_C:Number

BUTTON_Z

static public BUTTON_Z:Number

Method Detail

isDown

public function isDown(buttonCode):Boolean

Use this function to check if a Nunchuo button is pressed.

Parameters

buttonCodeOne of the Nunchuk.BUTTON_<name> constants.

Return

True if the button is pressed, false if not.

getStickX

public function getStickX():Number

This function returns the current X value of the Nunchuk's thumbstick. The thumbstick may report a value between -128 and +128. The value is 0 when the stick is centered.

Please note that this function does not provide any useful information at this time. It is included for completeness and forward compatibility only.

Return

An integer between -128 and +128.

getStickY

public function getStickY():Number

This function returns the current Y value of the Nunchuk's thumbstick. The thumbstick may report a value between -128 and +128. The value is 0 when the stick is centered.

Please note that this function does not provide any useful information at this time. It is included for completeness and forward compatibility only.

Return

An integer between -128 and +128.

addEventListener

public function addEventListener(type:String, listener:Function):Void

This function can be used to register an event listener for any of the following events:

  • buttondown - One of the Wii Remote buttons has been pressed.
  • buttonup - One of the Wii Remote buttons has been released.
When an event occurs, the passed-in function gets called with a parameter containing information about the event. All events attach a variable to the parameter called "identity". This is the id of the remote that fired the event. Each event type may have additional variables attached.

Here is a list of possible variables and the event types they are attached to:
  • buttonCode - buttondown, buttonup
Here's an example of how this function might be used:
 Wii.getRemote(1).getAttachment().addEventListener("buttondown", onButtonDown);
 
 function onButtonDown(event)
 {
     if(event.buttonCode == Nunchuk.BUTTON_Z)
     {
         trace("The Z button was pressed on the nunchuk "+
               "attached to remote #"+event.identity);
     }
 }

Parameters

typeA string representing the type of event to listen for.
listenerThe function to call when the event is fired.

removeEventListener

public function removeEventListener(type:String, listener:Function):Void

This function removes a listener previously registered with addEventListener.

Parameters

typeA string representing the type of event to listen for.
listenerThe function to call when the event is fired.