나는 작업 스크립트가 작동하는 웹 사이트에서 엔터테인먼트로 사용하기 위해이 뱀 버전을 편집하려고합니다. 내 문제는 나에게 의미가없는 것처럼 보이는 1010 오류입니다. 나는 성공하지 않고 디버깅을 시도했다.ActionScript 3.0 오류 1010
TypeError: Error #1010: A term is undefined and has no properties. at Main/onEnterFrame()
전체 코드는 이것이다 :
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
을 그리고 내 뱀 음식을 먹는 때마다 (그래서 말), 다음과 같은 에러가 발생합니다
인쇄 나타나는 첫 번째 출력은 다음과 같다 :
package{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event; //used for ENTER_FRAME event
public class Main extends MovieClip{
const speed:int = 20;//speed of the snake
var score:int;
var vx:int;
var vy:int;
var head:SnakePart;
var gFood;
var SnakeDirection:String;
var snake:Array;
public function Main(){
init();
}
function init():void {
//Initialize everything!
vx = 1; vy = 0;
score = 1;
snake = new Array();
SnakeDirection = "";
//add food to the stage
addFood();
//add snakes head to the stage
head = new SnakePart();
head.x = stage.stageWidth/2;
head.y = stage.stageHeight/2;
snake.push(head);
addChild(head);
stage.addEventListener(KeyboardEvent.KEY_UP , onKeyUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN , onKeyDown);
addEventListener(Event.ENTER_FRAME , onEnterFrame);
//ENTER_FRAME listener is attached to main class and not to the stage directly
}
//This function will add food to the stage
function addFood():void {
if(score%2==0){
gFood = new SnakePart();
}else{
gFood = new Food();
}
gFood.x = 50 + Math.random()*(stage.stageWidth-100);
gFood.y = 50 + Math.random()*(stage.stageHeight-100);
addChild(gFood);
}
//this function will reset the game
function reset():void {
removeChild(gFood);
addFood();
head.x = stage.stageWidth/2;
head.y = stage.stageHeight/2;
vx = 1;vy = 0;
for(var i = snake.length-1;i>0;--i){
removeChild(snake[i]);
snake.splice(i,1);
}
}
function onKeyDown(event:KeyboardEvent):void{
if(event.keyCode == Keyboard.LEFT){
SnakeDirection = "left";
}else if (event.keyCode == Keyboard.RIGHT) {
SnakeDirection = "right";
}else if (event.keyCode == Keyboard.UP) {
SnakeDirection = "up";
}else if (event.keyCode == Keyboard.DOWN) {
SnakeDirection = "down";
}
}
function onKeyUp(event:KeyboardEvent):void {
if(event.keyCode == Keyboard.LEFT) {
SnakeDirection = "";
}else if(event.keyCode == Keyboard.RIGHT) {
SnakeDirection = "";
}else if(event.keyCode == Keyboard.UP) {
SnakeDirection = "";
}else if(event.keyCode == Keyboard.DOWN){
SnakeDirection = "";
}
}
function onEnterFrame(event:Event):void {
//setting direction of velocity
if(SnakeDirection == "left" && vx != 1) {
vx = -1;
vy = 0;
//head.rotate(-90);
}else if(SnakeDirection == "right" && vx != -1) {
vx = 1;
vy = 0;
}else if(SnakeDirection == "up" && vy != 1) {
vx = 0;
vy = -1;
}else if(SnakeDirection == "down" && vy != -1) {
vx = 0;
vy = 1;
}
//collison with stage
if(head.x - head.width/2 <= 0){
score = 0;
reset();
}
if(head.x + head.width/2 >= stage.stageWidth){
score = 0;
reset();
}
if(head.y - head.height/2 <= 0){
score = 0;
reset();
}
if(head.y + head.height/2 >= stage.stageHeight){
score = 0;
reset();
}
//move body of the snake
for(var i = snake.length-1;i>0;--i){
snake[i].x = snake[i-1].x;
snake[i].y = snake[i-1].y;
}
//changing the position of snake's head
head.x += vx*speed;
head.y += vy*speed;
//collision with tail
for(var i = snake.length-1;i>=1;--i){
if(snake[0].x == snake[i].x && snake[0].y == snake[i].y){
reset();
break;
}
}
//collision with food
if(head.hitTestObject(gFood)){
score += 1;
removeChild(gFood);
addFood();
var bodyPart;
if(score%2==0){
bodyPart = new Food();
}else{
bodyPart = new SnakePart();
}
bodyPart.x = snake[snake.length - 10].x;
bodyPart.y = snake[snake.length - 10].y;
snake.push(bodyPart);
addChild(bodyPart);
}
//display scores
txtScore.text = String(score);
}
}
}
아무 것도 묻지 않아도됩니다! 우리의 대화를 기반으로
이
첫 번째 것들 먼저 ... 플레이어의 플래시 디버그 버전을 설치하려면 런타임 에러. (http://www.adobe.com/support/flashplayer/downloads.html) 그런 다음 문제의 위치를 쉽게 볼 수 있도록 오류 출력을 게시하십시오. 그 onEnterFrame 메서드에는 null 매개 변수가 있습니다. head, stage, snake 또는 txtScore – mihai
@mihai 감사합니다. 정말 도움이되었습니다. 그러나 나는 두 번째 문제가있다. 뱀의 머리를 회전 방향에 맞게 회전하려고합니다. 회전이 함수가 아님을 알려줍니다. 'head.rotate (-90); –
@mihai 업데이트 : 회전으로 변경했습니다. ** TypeError : 오류 # 1006 : 값이 함수가 아닙니다. ** –