Main.as
package{
import flash.display.MovieClip;
import flash.events.*;
public class Main extends MovieClip {
public var _root:MovieClip;
public var monsterContainer:MovieClip = new MovieClip();
public var delay = 30;
public function Main(){
addEventListener(Event.ADDED, beginClass);
addEventListener(Event.ENTER_FRAME, enterFrameEvents);
}
function beginClass(e):void{
_root = MovieClip(root);
}
function enterFrameEvents(e):void{
addChild(monsterContainer);
delay -= 1;
if(delay <= 0){
var spawn:Slime = new Slime();
spawn.x = startPoint.x;
spawn.y = startPoint.y;
monsterContainer.addChild(spawn);
delay = 30;
}
}
}
Arrow.as
package{
import flash.display.MovieClip;
import flash.events.*;
public class Arrow extends MovieClip {
public var _root:MovieClip;
public var facingID;
public function Arrow(){
addEventListener(Event.ADDED, beginClass);
addEventListener(Event.ENTER_FRAME, enterFrameEvents);
}
function beginClass(e):void{
_root = MovieClip(root);
}
function enterFrameEvents(e):void{
trace(_root.monsterContainer == null);
}
}
Enemy.as
package{
import flash.display.MovieClip;
import flash.events.*;
public class Enemy extends MovieClip {
public var _root:MovieClip;
//Status
public var monsterSpeed;
public var facing = "Right";
//CallingArrow
public var down:Down = new Down();
public function Enemy(){
addEventListener(Event.ADDED, beginClass);
addEventListener(Event.ENTER_FRAME, enterFrameEvents);
}
function beginClass(e):void{
_root = MovieClip(root);
}
function enterFrameEvents(e):void{
//Facing Movement
if(_root.pausing == false){
if(facing == "Right"){
this.x += monsterSpeed;
}else if(facing == "Left"){
this.x -= monsterSpeed;
}else if(facing == "Down"){
this.y += monsterSpeed;
}else if(facing == "Up"){
this.y -= monsterSpeed;
}
}
}
}
Down.as
package {
import flash.display.MovieClip;
import flash.events.*;
public class Down extends Arrow {
public function Down(){
facingID = "Down";
}
}
Slime.as
package {
import flash.display.MovieClip;
import flash.events.*;
public class Slime extends Enemy {
public function Slime(){
monsterSpeed = 5;
}
}
并且时间轴上没有其他代码,只有stop();
我收到1119错误,当我想访问粘液内的movieClip时,我给它实例名称的怪物,请帮帮忙!
下载链接:http://www.mediafire.com/download/hz5tptkgftwdipw/Tower_Defense.rar
它只有15KB并且使用CS6请帮助!
答案 0 :(得分:1)
您共享的代码超出了您可能需要的代码(包括.rar文件)。要找到问题的原因(以及StackOverflow上的问题)需要知道您正在编程的哪一行遇到此错误。如果您使用的是Flash IDE CS6,则可以通过转到发布设置并启用“允许调试”来启用。这将带来你的模棱两可的错误......
null object reference at myDocument/doSomething()
......更清楚......
null object reference at myDocument/doSomething() package\myClass.as:20
...现在表示代码中的哪一行可以查找您的问题。
使用调试编译模式打开调试控制台。这将使您立即查看相关代码行,以及调用堆栈和所有可用变量的状态。没有程序员就没有它。
Enemy.monster
这是问题的症结所在:在某个地方,你正在调用Enemy.monster
,并且你的Enemy
类中没有被称为(方法或其他)的属性。