1119:对可能未定义的属性的怪物通过静态类型的敌人参考访问。 AS3静态、怪物、属性、敌人

2023-09-08 15:03:00 作者:^老子就要你

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

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

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

Down.as

package  {
import flash.display.MovieClip;
import flash.events.*;


public class Down extends Arrow {

    public function Down(){

        facingID = "Down";
    }
}

Slime.as

Slime.as

package  {
import flash.display.MovieClip;
import flash.events.*;


public class Slime extends Enemy {

    public function Slime(){

        monsterSpeed = 5;

    }
}

和存在的时间轴没有额外的code就停止();

and there is no additional code on timeline just stop();

我得到了1119的错误,当我想访问一个影片剪辑内粘液,我给它的怪物实例名称,请大家帮忙!

I got 1119 error, when i want to access a movieClip inside slime, i give it monster for the instance name, please help !

下载链接: http://www.mediafire.com/download/hz5tptkgftwdipw/Tower_Defense .rar程序

这是只有15KB和使用CS6请帮帮忙!

It's only 15KB and using CS6 Please help !

推荐答案

在code你分享比你更可能需要(.rar文件包括在内)。要找到你(和那些计算器)需要了解哪些线要编程运行到该错误的问题的原因。如果您使用的是Flash IDE CS6中,可以将您的发布设置并启用允许调试中启用。这将带你暧昧的错误...

Turn on Debugging

The code you're sharing is more than you probably need (.rar file included). To find the cause of the problem you (and those on StackOverflow) need to know what line you're programming is running into this error. If you're using Flash IDE CS6, the can be enabled by going to your publish settings and enabling "Permit Debugging". This will take your ambiguous error...

在myDocument中/ DoSomething的()空对象引用

...一个更清晰...

...to a much clearer...

在myDocument中/ DoSomething的()包\ myClass.as空对象引用:20

...现在表示在code这行来寻找你的问题。

...which now denotes which line in your code to look for your issue.

使用调试编译模式,弹出调试控制台。这将为您提供即时看看code,这个行,以及调用堆栈,以及所有可用的变量的状态。任何程序员都应该没有吧。

Use the debugging compile mode to bring up the Debug Console. This will provide you with an immediate look at the line of code in question, as well as the Call Stack, and the state of all available Variables. No programmer should be without it.

这是问题的症结所在:什么地方,你呼吁 Enemy.monster ,且对你的敌人无属性类就是所谓的(方式或其他方式)。

This is the crux of the issue: somewhere, you're calling on Enemy.monster, and there is no property on your Enemy class that's called that (method or otherwise).