windigo
windigo

Reputation: 35

Recieving incorrect number of arguments error on a class that calls for zero

I've made a very simple 'game' where a circle is created and when clicked a new circle is added and clicking the new circle adds another while clicking any old circles 'ends' the game. I'm going to have a simple endgame screen with a restart button. I apologize if the code is messy, it is for practice in FlashDevelop.

The problem is I am trying to call my "endGame" class function in Main but I receive the error: "(58): col: 5 Error: Incorrect number of arguments. Expected 1." Line 58 is my call to endGame()

The weird part is that I receive the error even with endGame completely empty. I've posted both sections below and marked (**) the endGame call in main.

Main class

package Fun
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Shape;
import flash.events.MouseEvent;

public class Main extends Sprite 
{

    public var circles:Array;

    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        // entry point

        makeacircle()
    }

    public function makeacircle():void
    {
        circles = new Array();
        var addcirc:addcircle;
        addcirc = new addcircle((Math.random() * 999999))
        circles.push(addcirc)
        addChild(addcirc)
        addcirc.x = 300
        addcirc.y = 200
        addEventListener(eventclass.LOOP, movecirc);

        addcirc.addEventListener(MouseEvent.CLICK, transition )

        function transition(e:MouseEvent):void
        {
            addcirc.removeEventListener(MouseEvent.CLICK, transition);
            dispatchEvent ( new eventclass(eventclass.LOOP))
            addcirc.addEventListener(MouseEvent.CLICK, gameover)
        }
        function gameover(e:MouseEvent):void
        {
            for each (var circle:addcircle in circles)
            {
                removeChild(circle)
            }

            circles.length = 0
**          endGame()
        }
    }


    public function movecirc(Eventclass:eventclass):void
    {

        var addcirc:addcircle;
        addcirc = new addcircle((Math.random() * 1000000))
        circles.push(addcirc);
        addcirc.addEventListener(MouseEvent.CLICK, looper)
        addChild(addcirc);

        for each (var circle:addcircle in circles)
        {
            circle.x = (Math.random() * 600) 
            circle.y = (Math.random() * 400)
        }

        function looper(e:MouseEvent):void
        {
            addcirc.removeEventListener(MouseEvent.CLICK, looper)
            dispatchEvent ( new eventclass( eventclass.LOOP))
            addcirc.addEventListener(MouseEvent.CLICK, gameover)
        }

        function gameover(e:MouseEvent):void
        {
            for each (var circle:addcircle in circles)
            {
                removeChild(circle)
            }

            circles.length = 0

        }
    }
}
}

endGame

package Fun 
{
import flash.display.Sprite;

public class endGame extends Sprite 
{

    public function endGame():void 
    {

    }

}

}

Without the call to endGame() the code runs perfect and everything I want occurs. I'm just not sure why the endGame function is claiming to require arguments.

Upvotes: 0

Views: 39

Answers (1)

SharpEdge
SharpEdge

Reputation: 1762

We have several problems here.

First: you should ALWAYS use semicolon, not when you remember. Second: the cause of problem is you are calling endGame() as if it's a function

You have a Class endGame so this is the correct use of it:

var eg : endGame = new endGame();

From what i see you should learn a bit more about OOP before using Classes

Upvotes: 1

Related Questions