views:

143

answers:

3

Ok, I have raise these question a thousand times and so far no ones been able to help me. I am raising again because I discovered something new. In the past I haven't been able to create parameters for class objects, every time when I do so I get the following error

1136: Incorrect number of arguments.  Expected 0.

I notice that my classes that are subclasses to Movie Clip or Sprite are able to have constructor parameters, but my classes that are sub class to a subclass aren't. is there any reason behind this?

var cloud = new Cloud(5, 4);

package com.objects{
    import flash.events.Event;
    import flash.utils.*;

    public class Cloud extends gameObject {

        public var maxSpeed = 30;
        public var minSpeed = 5;
        public var cspeed:Number = 0;

        public function Cloud(min:Number = 0, max:Number = 0):void
        {
            var rand = Math.ceil(Math.random() * totalFrames);
            gotoAndStop(rand);
        }

        public function rand(min:Number, max:Number):void
        {
            maxSpeed = max;
            minSpeed = min;
            cspeed = (Math.ceil(Math.random() * maxSpeed)+ minSpeed);
        }

        override public function updateObject():void
        {
            eApi.setChildIndex(this, (eApi.numChildren - 1));
            y += cspeed;

            if(y > 800)
                garbage = true;
        }


    }
}

Here is the parent class

package com.objects {

    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.*;
    import flash.utils.getTimer;

    public class gameObject extends MovieClip implements IgameObject
    {
        public static var EG:Engine;
        public var wPosX:Number = 0;
        public var wPosY:Number = 0;

        public var vPosX:Number = 0;
        public var vPosY:Number = 0;

        public var px:Number = 0;
        public var py:Number = 0;

        public var right:Number = 0;
        public var bottom:Number = 0;
        public var left:Number = 0;
        public var top:Number = 0;
        public var centerx:Number = 0;
        public var centery:Number = 0;
        static public var eApi:EngineApi;
        public var health:Number = 1;
        public var maxHealth:Number = 1;
        protected var lastTime:Number;
        public var ts:TargetSystem;

        public var col:Number;
        public var row:Number;
        public var map:Number;
        public var dead:Boolean = false;

        public var garbage:Boolean = false;

        public function gameObject():void {

        }//End Constructor

        static public function addEngine(e:EngineApi):void
        {
            eApi = e;
        }

        public function updateObject():void
        {

        }
        public function Attack(dir:Number = -40):void
        {

        }

        public function GarbageCollect():gameObject
        {
            return this;
        }

        public function getTime():int
        {
            var time:int = getTimer();
            return time;
        }
    }
}
+2  A: 

Without seeing any code, I can only offer a few vague, "Is the computer plugged in?"-style suggestions:

-Check to make sure there are no existing classes with the same name as your subclass. Try appending some nonsense at the end of your class (i.e. "MyClassFl4134qq") to check for collisions - if the change makes it work, that's your problem.

-Check to make sure the class you're subclassing isn't marked 'final'.

-Check to make sure any calls to the 'super(...)' constructor have the correct number of arguments for the superclass, not for the subclass.

-Check your variable declarations. Make sure the type of whatever object you're assigning to that variable matches the type you declared it as.

If I had to bet, I'd say you probably have a class name conflict (see 1st suggestion).

iandisme
Sorry, its just I posted the code before and no one knew what it was. I was trying to get reason for why it could not be working on this post. But above i added the code.
numerical25
+2  A: 

It you are attaching a symbol via Flash IDE to a custom class (MovieClip, Sprite,..) who is taking parameter flash doesnt know how to instanciate such a class, how can it guess the parameter you are expecting ?

It can only instanciate class with no arguments, you have to rely on another way to init your class later or provide a default parameter.

Patrick
So are you saying that all custom classes that have a symbol attached to it can not use constructor arguements
numerical25
I think you might be right cause it only works for classes that do not have symbols attached to it!! I dont understand the reason why that well. But the pieces are coming together. could you please elaborate more. If you can. Thanks!!
numerical25
I say that if you have a symbol attached to custom class requiring arguments, it cant be instanciated from IDE since the IDE cannot guess the values of the arguments you are expecting
Patrick
+1  A: 

You have to implement a constructor in the sub-sub-class. Otherwise flash will substitute in an empty constructor that doesn't take any arguments.

abc
Hmm good answer... perhaps it was wrong of me to assume that he implemented the constructor he is trying to call. +1
iandisme