AIRControl is a native extension that allows the use of game controllers. The extension has the hability to read controller information such as the current value for any axis, POV hat switch, or a button status. It’s possible to listen to specific events, such as when a controller is attached or detached.

The extension has a list with all active controllers, each one indexed by an integer. Using the controller index number, a developer can read information from a specific controller. Every event fired by the extension (e.g. axis change) has the index of the source controller, so it’s possible to react accordingly.

Sample

/*
Copyright (C) 2012-2013 Alexander O'Mara alexomara.com

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.
*/

//Add the event listeners to detect controller attachment.
AIRControl.addEventListener(AIRControlEvent.CONTROLLER_ATTACH, controllerAttach);
AIRControl.addEventListener(AIRControlEvent.CONTROLLER_DETACH, controllerAttach);

private function controllerAttach(e:AIRControlEvent):void {
	//Fired on controller attach and detach.
	switch(e.type) {
		case AIRControlEvent.CONTROLLER_ATTACH:
			//Add event listeners for controller state changes.
			e.controller.addEventListener(AIRControlControllerEvent.AXIS_CHANGE, controllerEvent);
			e.controller.addEventListener(AIRControlControllerEvent.BUTTON_CHANGE, controllerEvent);
			e.controller.addEventListener(AIRControlControllerEvent.POV_CHANGE, controllerEvent);
			//Log the attach and a few key variables.
			trace("AIRControlEvent.CONTROLLER_ATTACH, controllerIndex=" + e.controllerIndex + ", controller.ID=" + e.controller.ID + ", controller.name=\"" + e.controller.name + "\"");
		break;
		case AIRControlEvent.CONTROLLER_DETACH:
			//Remove the event listeners.
			e.controller.removeEventListener(AIRControlControllerEvent.AXIS_CHANGE, controllerEvent);
			e.controller.removeEventListener(AIRControlControllerEvent.BUTTON_CHANGE, controllerEvent);
			e.controller.removeEventListener(AIRControlControllerEvent.POV_CHANGE, controllerEvent);
			//Log the detach and a few key variables.
			trace("AIRControlEvent.CONTROLLER_DETACH, controllerIndex=" + e.controllerIndex + ", controller.ID=" + e.controller.ID + ", controller.name=\"" + e.controller.name + "\"");
		break;
	}
}

private function controllerEvent(e:AIRControlControllerEvent):void {
	//Log information about what controller fired the event.
	switch(e.type) {
		case AIRControlControllerEvent.AXIS_CHANGE:
			trace("AIRControlControllerEvent.AXIS_CHANGE, controller.ID=" + e.controller.ID + ", controller.name=\"" + e.controller.name + "\", elementIndex=" + e.elementIndex + "\", element.position=" + e.element["position"]);
		break;
		case AIRControlControllerEvent.POV_CHANGE:
			trace("AIRControlControllerEvent.POV_CHANGE, controller.ID=" + e.controller.ID + ", controller.name=\"" + e.controller.name + "\", elementIndex=" + e.elementIndex + "\", element.X=" + e.element["X"] + ", element.Y=" + e.element["Y"]);
		break;
		case AIRControlControllerEvent.BUTTON_CHANGE:
			trace("AIRControlControllerEvent.BUTTON_CHANGE, controller.ID=" + e.controller.ID + ", controller.name=\"" + e.controller.name + "\", elementIndex=" + e.elementIndex + "\", element.down=" + e.element["down"]);
		break;
	}
}

private function enterFrame(e:Event):void {
	//Update the controller states.
	AIRControl.update();
	var text:String;
	var controller:AIRControlController;
	var i:uint;
	//Make sure the current controller index is not out of range.
	while(currentIndex && currentIndex > AIRControl.controllersTotal-1) {
		currentIndex--;
	}
	//Check if controllers are attached.
	if(AIRControl.controllersTotal) {
		//Get the controller at the specified index. NOTE: It is usually better to match controllers on attach/detach than requesting specific indexes.
		controller = AIRControl.controller(currentIndex);

		//Set the current controller header.
		currentControllerHeader.text = "Current Controller " + (currentIndex+1) + "/" + AIRControl.controllersTotal + ", index: " + currentIndex + "";

		//Get the details about the controller.
		text = "ID:\n\t" + controller.ID + 
			"\n\nname:\n\t" + controller.name + 
			"\n\nvendorID:\n\t" + controller.vendorID + 
			"\n\nproductID:\n\t" + controller.productID + 
			"\n\nAXIS_X:\n\t" + controller.AXIS_X + 
			"\n\nAXIS_Y:\n\t" + controller.AXIS_Y + 
			"\n\nAXIS_Z:\n\t" + controller.AXIS_Z + 
			"\n\nAXIS_R:\n\t" + controller.AXIS_R + 
			"\n\nAXIS_U:\n\t" + controller.AXIS_U + 
			"\n\nAXIS_V:\n\t" + controller.AXIS_V;

		//Loop over the axes.
		text += "\n\naxes (" + controller.axesTotal + "):";
		for(i = 0; i < controller.axesTotal; i++) {
			text += "\n\t" + controller.axis(i).position;
		}
		//Loop over the POV hat switches.
		text += "\n\npovs (" + controller.povsTotal + "):";
		for(i = 0; i < controller.povsTotal; i++) {
			text += "\n\tX: " + controller.pov(i).X + " \tY: " + controller.pov(i).Y;
		}
		//Loop over the buttons.
		text += "\n\nbuttons (" + controller.buttonsTotal + "):\n\t";
		for(i = 0; i < controller.buttonsTotal; i++) {
			text += controller.button(i).down ? "1" : "0";
		}
	}
}
Air Native Extension, Mac, Windows . URL.