actionscript 3 - AS3错误1063 -与(看似)正确的参数数量



所以我一直在尝试着创造一款游戏,而在这一点上我只是想为基于贴图的游戏世界创造一个基本框架,就像《Pokemon》或其他游戏一样。

我现在的问题是一个荒谬的;在修复了其他几个错误之后,我仍然在两个不同的地方得到ArgumentError #1063,在这两种情况下,我都传入了适量的参数(都是构造函数),错误告诉我传入了0。

下面是第一个的相关代码:

public function Main()
    {
        stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 0, true);
        stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, false, 0, true);
        stage.addEventListener(Event.ENTER_FRAME, act, false, 0, true);
        key = new KeyObject(stage);
        overWorld = new Map(stage);
        stage.addChild(overWorld);
    }

(overWorldMap变量,上面用public var overWorld:Map;声明)

:

public function Map(stageRef:Stage)
    {
        key2 = new KeyObject(stageRef);
        currentMap = MapArrays.testMap;
        x = 0;
        y = 0;
        initializeTiles();
    }

我用它需要的stage引用调用Map()构造函数,并且它将此作为错误输出:

ArgumentError: Error #1063: Argument count mismatch on Map(). Expected 1, got 0.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at Main()

此外,initializeTiles()函数保存了这两个错误中的第二个。下面是相应的代码:

public function initializeTiles()
    {           
        for(var i:int = 0; i < 25; i++)
        {
            for(var j:int = 0; j < 20; j++)
            {
                var temp:String = ("tile"+i+"_"+j);
                this[temp] = new Tile(currentMap, (i+10), (j+10), (i * 30), (j * 30))
            }
        }
    }

Tile()构造函数:

public function Tile(mapArr:Array, inX:int, inY:int, xpos:int, ypos:int)
    {
        mapArray = mapArr;
        arrX = inX;
        arrY = inY;
        x = xpos;
        y = ypos;
        determineTile();
    }

这是吐出的错误(500次,20x25):

ArgumentError: Error #1063: Argument count mismatch on Tile(). Expected 5, got 0.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at Map()
at Main()

只是解释一下,mapArr/mapArray/currentMap是描述活动地图集的整数数组,inX/arrX是地图中给定瓷砖的x位置(inY/arrY当然是y位置),xposypos只是瓷砖在屏幕上的位置(每个瓷砖是30px × 30px)。determineTile()只是查找int mapArray[arrX][arrY]并相应地更改tile的属性和图像。MapArrays是我在Map类中创建并导入的public dynamic class, import MapArrays;

无论如何,任何帮助与这个问题将不胜感激。如果有人认为在其他地方可能存在问题,我可以编辑发布更多代码,但这些是唯一调用构造函数的地方,并且在我的输出中出现前501个错误(还有一些,但它们是,因为这些构造函数失败了,因为它们是空引用错误)。我被困在这里,花了大量的时间稍微调整一些东西,到目前为止没有任何工作,我没有看到其他地方有人在使用正确数量的参数时得到这个错误。

如果你有任何TileMap实例放置在舞台上,这些实例将由Flash在运行时通过调用构造函数实例化(就像当你通过调用new Tile(...)创建Tile实例一样)。

因为你的TileMap类有自定义构造函数(带参数),Flash不能创建这些显示对象的实例,因为它不知道传递什么作为输入参数给构造函数-这就是为什么你得到错误。

通常最好不要将任何有代码备份的东西放在舞台上——只需从代码中创建这些实例,并在运行时将它们添加到舞台上。这是额外的工作,但它使您的设置更干净。

最新更新