开发者

AS3 not accepting constructor

开发者 https://www.devze.com 2022-12-18 19:36 出处:网络
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 f

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


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消