Acceleropmeter (스마트 폰용)로 볼을 제어 할 수있는 학교용 앱을 만들고 있는데, 공이 특정 Y 좌표에 도달하면 잃어 버리고 이동합니다. (당신이 게임을 잃었다 고 말한) 다른 프레임으로. 공을 수행하고 코드는 지금까지입니다 맞는지 :AS3 - 볼 타격 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 라인에 오류 (형식 오류가 말한다 : 오류 # 1009 :의 속성이나 메서드에 액세스 할 수 없습니다 null 객체 참조 at ballApp_Scene1_fla :: MainTimeline/moveBall() [ballApp_Scene1_fla.MainTimeline :: frame1 : 32) 이유가 무엇입니까? 이 문제를 어떻게 해결할 수 있습니까?
입니다? 어디서나 선언하거나 어디에서 초기화 할 것인지 모르겠다. –