Question

So I've been toying with the idea of building a game, and at this point I'm just trying to get a basic framework down for a tile-based over-world, like in Pokemon or others.

The issue I'm having now is an absurd one; after fixing several other errors I'm still getting ArgumentError #1063 in two different places, and in both cases I pass the right amount of arguments in (both are constructors) and the error tells me I passed in 0.

Here's pertinent code for the first one:

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);

    }

(overWorld is a Map var, declared above with public var overWorld:Map;)

and:

public function Map(stageRef:Stage)
    {
        key2 = new KeyObject(stageRef);
        currentMap = MapArrays.testMap;

        x = 0;
        y = 0;

        initializeTiles();
    }

I'm calling the Map() constructor with the stage reference that it needs, and it's spitting out this as the error:

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()

In addition, that initializeTiles() function holds the second of these two errors. Here's the code for that:

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))
            }
        }

    }

and the Tile() constructor:

public function Tile(mapArr:Array, inX:int, inY:int, xpos:int, ypos:int)
    {

        mapArray = mapArr;
        arrX = inX;
        arrY = inY;
        x = xpos;
        y = ypos;
        determineTile();

    }

This is the error that spits out (500 times, 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()

Just to explain some, mapArr/mapArray/currentMap are Arrays of ints that describe the active mapset, inX/arrX is the x location of a given tile within the map (inY/arrY is of course the y location), and xpos and ypos are just where the tile sits on the screen (each tile is 30px by 30px). determineTile() just looks up the int mapArray[arrX][arrY] and changes the tile's attributes and image accordingly. MapArrays is a public dynamic class I created and imported in the Map class with import MapArrays;

Anyways, any help with this issue would be much appreciated. I can edit to post more code if someone thinks there may be an issue somewhere else, but these are the only places the constructors are called and the first 501 errors in my output (there are a few more, but they are because these constructors failed as they are null reference errors). I've been stuck here for a hefty chunk of time tweaking things slightly and nothing has worked thus far, and I don't see anywhere else where someone is getting this error while using the right amount of arguments.

Thanks in advance.

Was it helpful?

Solution

If you have any Tile or Map instances placed on the stage, those instances would be instantiated by Flash at run-time by calling the constructor (just like when you create an instance of Tile by calling new Tile(...).

Since your Tile and Map classes have custom constructors (that take parameters), Flash cannot create an instance of those display objects because it doesn't know what to pass as input parameters to the constructor - this is why you get the error.

Usually it's best not to put anything on the stage that has code backing it up - just create those instances from code and add them to the stage at run-time. This is extra work but it keeps your setup cleaner.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top