我正在为学校制作一个小应用程序,您可以在其中使用 Acceleropmeter(用于智能手机)控制球,我想要这样,如果球达到某个 Y 坐标,您会输掉并转到另一帧(它说您有输掉比赛)。'已经完成了球,到目前为止的代码是这样的:
var fl_Accelerometer:Accelerometer = new Accelerometer();
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
cBall.x -= event.accelerationX * 40;
cBall.y += event.accelerationY * 40;
}
cBall.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(evt:Event){
// this is to stop the ball when it tries to exit the sreen
if(cBall.x > (480-cBall.width/2)){
cBall.x = 480-cBall.width/2;
}
// except for this, that stops the ball not if it touches the end of the screen, but if it reaches a certain Y coordinate
if(cBall.y > (780-cBall.width/2)){
gotoAndStop(3);
}
if(cBall.x < (0+cBall.width/2)){
cBall.x = 0+cBall.width/2;
}
if(cBall.y < (0+cBall.width/2)){
cBall.y = 0+cBall.width/2;
}
}
每当我尝试该应用程序时,它都会显示第 32 行有错误(TypeError: Error #1009: Cannot access a property or method of a null object reference. at ballApp_Scene1_fla::MainTimeline/moveBall()[ballApp_Scene1_fla.MainTimeline::帧 1:32) 为什么?我怎样才能解决这个问题?