Accelerometer function issue
Hi guys,
I'm very new to flash and AS3 and I'm getting an annoying issue. I'm currently trying to make a simple game using accelerometer controls, and it works fine for the first level, but as soon as it tries to jump to either another scene or frame 2 (I've tried having the different levels on either scenes or frames, and the error occurs regardless) I'm getting this error: TypeError: Error #1009: Cannot access a property or method of a null object reference.
From looking around on the web I can see that it's trying to load something that's not there, but I'm not sure at what point it's stopped existing. Do I need to terminate the function at the end of the 1st scene and then re-initialize?
Here is the first frame's code, the error message is: "TypeError: Error #1009: Cannot access a property or method of a null object reference. at ball_game_fla::MainTimeline/onAccUpdate()[ball_game_fla.MainTimeline::frame1:17]"
import flash.sensors.Accelerometer;import flash.events.AccelerometerEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
var isFalling:Boolean = false;
var theAcc: Accelerometer = new Accelerometer();
theAcc.setRequestedUpdateInterval(10);
theAcc.addEventListener(AccelerometerEvent.UPDATE,onAccUpdate);
stop();
function onAccUpdate(e:AccelerometerEvent)
{
ball.x -= (e.accelerationX * 10);
ball.y += (e.accelerationY * 10);
dummyBall.x = ball.x;
dummyBall.y = ball.y;
ballShadow.x = ball.x + 5;
ballShadow.y = ball.y + 5;
if (ball.x < 0){
ball.x = 0;
}else if (ball.x > stage.stageWidth){
ball.x = stage.stageWidth;
}
if (ball.y < 0){
ball.y = 0;
}else if (ball.y > stage.stageHeight){
ball.y = stage.stageHeight;
}
if(dummyBall.hitTestPoint ( hole.x, hole.y, true ) && isFalling == false){
isFalling = true;
hole.gotoAndPlay(2);
ball.visible = false;
ballShadow.visible = false;
dispatchEvent(new Event("finished", true));
}
}
Any pointers would be really useful
