您能否查看我的代码并告诉我为什么会收到此错误:
TypeError:错误 #1009:无法访问空对象引用的属性或方法。在 Arm/update()
我没有像我刚刚学到的那样使用文档类,也无法让它们工作。这是我开始的教程:http ://eyes-squared.co.uk/blog/making-a-copter-style-game-the-projects/
主要代码:
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();
}
}
}
}
}