I'm making an animation for mobile that moves an image across the screen when the device is tipped. Here's the code I've used to achieve that:
var fl_Accelerometer:Accelerometer = new Accelerometer();
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
Image1.x -= event.accelerationX * 300;
if (Image1.x < 56.75)
{
Image1.x = 56.75;
}
else if (Image1.x > 1856.75)
{
Image1.x = 1856.75;
}
}
I want to be able to turn Accelerometer input on and off when I click different buttons on the menu screen.
What I thought was to have an integer equal to 1 before I click any buttons; so I do (accelerationX*300)*[that integer] and the accelerometer is enabled. Then I click a 'disable' button, that 1 becomes a 0 and the accelerometer is disabled. Then click another button and the integer becomes 1 again.
How do I do this and is there an easier way?