Here is a piece of code for Android where it need to start in first .as file for your mobile.
iOS and Desktop works great but Android needed this code if it can help someone out in the future why not.
`
if (OSVERSIONN == 2)
{
var gameInput:GameInput = new GameInput();
var gameInput2:GameInput = new GameInput();
var device:GameInputDevice;
var control:GameInputControl;
var device2:GameInputDevice;
var control2:GameInputControl;
gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, GIE_added);
}
function GIE_added(gameInputEvent:GameInputEvent):void
{
//
trace("Controller Added! GameInput.numDevices is " + GameInput.numDevices);
//
// trace("GameInput.getDeviceAt: "+ GameInput.getDeviceAt(1));
//Controller #1 - lazy test
trace("GameInput.getDeviceAt: "+ GameInput.getDeviceAt(0));
device = GameInput.getDeviceAt(0);
//get all the buttons (loop through number of controls) and add the on change listener
//this indicates if a button pressed, and gets the value...
for(var i:int = 0; i<device.numControls; ++i){
control = device.getControlAt(i);
control.addEventListener(Event.CHANGE, GIE_onChange3);//capture change
//what buttons does it have (names)
trace("CONTROLS: "+control.id);
}
if (GameInput.numDevices == 2){
//Controller #1 - lazy test
device2 = GameInput.getDeviceAt(1);
trace("GameInput.getDeviceAt1: "+ GameInput.getDeviceAt(1));
idgamerpaddevice2 = int(device2);
//
//
trace("GameInput.getDeviceAt2: "+ idgamerpaddevice2);
if (device2 == null){}else{
//get all the buttons (loop through number of controls) and add the on change listener
//this indicates if a button pressed, and gets the value...
for(var i2:int = 0; i2<device2.numControls; ++i2){
control2 = device2.getControlAt(i2);
control2.addEventListener(Event.CHANGE, GIE_onChange3);//capture change
//what buttons does it have (names)
trace("CONTROLS: "+control2.id);
}
device2.enabled = true;
}
}
device.enabled = true;
}
function GIE_onChange3(event:Object):void
{
control = event.target as GameInputControl;
control2 = event.target as GameInputControl;
//To get the value of the press you can use .value, or minValue and maxValue for on/off
//var num_val:Number = control.value;
//
//constant stream (Axis is very sensitive)
// trace("control.id=" + control.id);
// trace("control.id2=" + control2.id);
// trace("control.value=" + control.value + " (" + control.minValue+" .. " + control.maxValue+")");
//
// trace("control.id=" + control.value);
// trace("control.id=" + control2.value);
idgamerpad2 = control.id;
idgamerpadcontrol2 = control.value;
// movingLeft = false;
// movingRight = false;
// movingDown = false;
// movingUp = false;
Game.main2.Changerr2(idgamerpad2,idgamerpaddevice2,idgamerpadcontrol2);
}
`
In the Game.as file use this function to read inputs
Also put main2 = this; in Game.as
public function Game()
{
main2 = this;
`
public function Changerr2(idgamerpad2:String,idgamerpaddevice2:int,idgamerpadcontrol2:Number):void
{
idgamerpad = idgamerpad2;
idgamerpaddevice = idgamerpaddevice2;
idgamerpadcontrol = idgamerpadcontrol2;
// trace("control.id3=" + idgamerpad);
// trace("control.id34=" + idgamerpaddevice);
// trace("control.id35=" + idgamerpadcontrol);
if(Menu_Category == 'Restart' && Menu_Target == 'GameStarted' && GameOverr_Start == 0 && GameOverr == 1 && GameOverMenu_Image.alpha == 0.9)
{
if(idgamerpad == 'BUTTON_4' && idgamerpadcontrol == 1 && idgamerpaddevice == 0 || (idgamerpad == 'BUTTON_96' && idgamerpadcontrol == 1 && idgamerpaddevice == 0) || (idgamerpad == 'Button A' && idgamerpadcontrol == 1 && idgamerpaddevice == 0))
{
GameoverContinue_2();
}
}
`