首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于Copter风格的道奇游戏AS3的错误代码#1009

用于Copter风格的道奇游戏AS3的错误代码#1009
EN

Stack Overflow用户
提问于 2013-04-14 19:21:10
回答 1查看 165关注 0票数 0

请您看一下我的代码,告诉我为什么我会收到这个错误:

TypeError:错误#1009:无法访问空对象引用的属性或方法。at Arm/update()

我是,而不是我刚刚学到的使用文档类的,无法让这些类工作。下面是我从下面开始的教程:http://eyes-squared.co.uk/blog/making-a-copter-style-game-the-projects/

主要代码:

代码语言:javascript
复制
stop();


import flash.events.Event;
import flash.events.MouseEvent;


var mouseIsDown = false; // mouse isn't held at start
var speed = 0; // no speed at the start
var score = 0; // start with no score!

// check for collisions every frame
addEventListener(Event.ENTER_FRAME, mainLoop);
// add 2 event listeners for the mouse button
stage.addEventListener(MouseEvent.MOUSE_DOWN, clicked);
stage.addEventListener(MouseEvent.MOUSE_UP, unclicked);

// explain the mouse functions
function clicked(m:MouseEvent) {
    mouseIsDown = true;
}

function unclicked(m:MouseEvent) {
    mouseIsDown = false;
}

//// explain the main game loop
function mainLoop(e:Event) {
    // update the score!
    score = score + 10;
    // update the text field
    Output.text = "Score: "+score;
    // move the player based on the mouse button
    if (mouseIsDown) {
        // take something off the speed
        speed -= 2; // accelerate upwards
    } else {
        speed += 2;
    }
    // limit the speed
    if (speed > 10) speed = 10;
    if (speed < -10) speed = -10;
    // move the player based on the speed
    firefly.y += speed;
    // loop through everything on screen
    for (var i = 0; i<numChildren; i++) {
        // check to see if this object is a block
        if (getChildAt(i) is Block || getChildAt(i) is Boundary || getChildAt(i) is Block2 || getChildAt(i) is Arm) {
            var b = getChildAt(i) as MovieClip;
            // this means the object is a block
            // check the block against the player object
            if (b.hitTestObject(firefly)) {
                // make an explosion
                for (var counter = 0; counter<12; counter++) {
                    // make a new Boom object
                    var boom = new Boom();
                    boom.x = firefly.x;
                    boom.y = firefly.y;
                    // randomly rotate boom
                    boom.rotation = Math.random()*360;
                    // randomly scale it
                    boom.scaleX = boom.scaleY = 0.5+Math.random();
                    // add the boom to the world
                    addChild(boom);
                }
                // hide the player
                firefly.visible = false;
                removeEventListener(Event.ENTER_FRAME, mainLoop);

                if(b.hitTestObject(firefly)){
                    nextFrame();
                }
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2013-04-14 23:24:04

提示是,您的错误引用了名为Arm的类/ MovieClip中的一个名为update()的函数,该函数未包含在初始帖子中。

假设类中没有任何代码,并且所有东西都在FLA中,那么查看名为Arm的对象的Flash中的Library面板,打开它,然后查看框架脚本中的update()函数。

特定的错误意味着您试图对尚未创建的对象(或其属性的属性)执行操作,或者不存在。例如,如果删除或重新标记了Arm符号中的命名对象,然后在update函数中引用该对象,则会遇到空对象错误。

如果您查看代码,并且仍然难以确定哪个对象为null,请尝试在update函数的每一行之间放置以下跟踪语句:

代码语言:javascript
复制
trace(1);
...
trace(2);
...

因为这是一个运行时错误,Flash将在每一行跟踪给定的数字,直到它碰到该错误,并删除线程。观察输出面板,看看哪些数字被跟踪,您就会知道,故障线路是直接跟踪的最高数字之后。然后,您可以考虑为什么该行上的某个内容可能为空。祝好运!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16003276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档