实际上没有被调用的继承方法

时间:2014-10-26 05:28:29

标签: actionscript-3 flash flash-cs6

我正在使用Adobe的Flash Pro CS6创建一个Flash游戏,我遇到了一个大错。我正在制作一个无尽的跑步者,我需要随机生成积木让玩家跳过并躲避。来自Java背景,这通常应该相当容易,但事实并非如此。以下是我的三个课程Box.asGroundBox.asRoofBox.as在不同的文件中(SO代码格式将它们组合在一起):

// Box.as:
package  {
    import flash.display.MovieClip;
    public class Box extends MovieClip {
        public static function getDefaultY():Number {
            return 258.75;
        }
        public function myToString():String {
            return "Box[" + this.x + "," + this.y + "]";
        }
    }
}

// GroundBox.as:
package {
    import flash.display.MovieClip;
    public class GroundBox extends Box {
        public function collidesWith(xPos:Number, yPos:Number):Boolean {
            return this.x <= xPos && xPos <= this.x + this.width && this.y <= yPos && yPos <= this.y + this.height;
        }
    }
}

// RoofBox.as:
package {
    import flash.display.MovieClip;
    public class RoofBox extends Box {
        public function collidesWith(xPos:Number, yPos:Number):Boolean {
            return this.x <= xPos && xPos <= this.x + this.width && this.y >= yPos && yPos >= this.y - this.height;
        }
    }
}

正如您所看到的,我的超级类Box有两个函数:public static function getDefaultY():Numberpublic function myToString():String(它被称为'myToString',因为我在尝试覆盖'toString时遇到错误“)。我遇到的问题是,当我创建var gBox:GroundBox = new GroundBox();时,我无法拨打gBox.y = Box.getDefaultY();trace(gBox.myToString());

给出错误代码:

TypeError: Error #1006: getDefaultY is not a function.
    at Dude_fla::MainTimeline/frame1()
TypeError: Error #1006: myToString is not a function.
    at Dude_fla::MainTimeline/updateBlocks()[Dude_fla.MainTimeline::frame1:244]
    at Dude_fla::MainTimeline/updateLoop()[Dude_fla.MainTimeline::frame1:20]

0 个答案:

没有答案