views:

601

answers:

6

I ask this question time and time again and havnt got an answer. Its driving me crazy evertytime I get it. Sometimes it works, and sometimes it doesnt. When I pass a object through the constructor, it gives me the error message. So I always got to make a second method to get it to work. Here is my code if anyone can please help me

var ds = new desertStorm(ship);

Above is the object i call and below is the class.

package com.objects{

    import flash.display.MovieClip

    public class desertStorm extends Stinger {

        private var turret1:Torret;
        private var swap:Boolean = false;
        private var target:Avatar;
        public function desertStorm(target:Object):void
        {
            this.target = target;
            health = 2;
            turret1 = new Torret();
            eApi.addGameChild(turret1);
        }

        override public function updateObject():void
        {
            if(!swap)
            {
                eApi.swapGameChildren(this, turret1);
                swap = true;
            }
            y += cspeed;
            turret1.x = x;
            turret1.y = (y + 40);
        }
    }
}

if anyone can help me out that would be great

A: 

The error you're seeing seems to be on this line:

eApi.addGameChild(turret1);

I would look into the eApi object and see if addGameChild accepts any parameters.

Gabriel McAdams
Its not. if I remove 'ship' from the desertStorm() param, and remove it from the constructors param, the error goes away
numerical25
Ive had this issue countless times before and I dont know if I got a bad copy or what
numerical25
Ive had these issues before and I usually just create another method to take in those parameters, but now its bugging me and I would rather do it the correct way
numerical25
Have you tried explicitly calling the super() constructor? (how many arguments does the constructor for Stinger have?)
Gabriel McAdams
A: 

Try adding the following line to your constructor:

super();

This will explicitly call the constructor of the base class and pass it zero arguments. It could be that if the base class's constructor is not called explicitly in this fashion it is called with the same arguments as the child class's constructor.

This is just a hunch, though; I can't remember the rules for constructors in ActionScript 3.

EDIT: It seems Gabriel McAdams came up with this before me, but I didn't see his comment in time.

Cameron
A: 

Updated Answer:#

This listing of compiler errors says:

You must explicitly call the constructor of the base class with a super() statement if it has 1 or more required arguments.

Given your error (1203: No default constructor found in base class com.objects:desertStorm.), it looks like you are extending desertStorm somewhere and need to call the super() function with the appropriate parameter.

This simple example given below will fail with this compiler error: 1203: No default constructor found in base class Class1.

Indicating that the issue is in the class that extends Class1.

So find whereever you're extending desertStorm and call the correct super-constructor.

Example:

package
{
    import flash.display.MovieClip;

    public class Class1 extends MovieClip
    {
        public function Class1(property:String)
        {
            super();
        }
    }
}

package
{
    import flash.display.MovieClip;

    public class Class2 extends Class1
    {
        public function Class2()
        {
            // You need to call the super constructor here.
            // super("Work!");
        }
    }
}

Original Answer:

If I remove ship from the parameter and keep public function desertStorm(target:Object):void. this is the error i get....
'1203: No default constructor found in base class com.objects:desertStorm.'
Im not sure what that means but it sounds like I dont have a constructor when I do

Whilst you do have a constructor, you don't have a default constructor.

If you have created any instances of desertStorm by dragging them from the library to the stage then you must define a default constructor, such as:

public function desertStorm():void
{
    super();

    // Do simple initialisation behaviour here.
}

This is because Flash doesn't know how to instantiate your class if it has a custom constructor - how can it?

Instead, move the other behaviour into an initialisation function that knows all about your target object:

public function init(target:Object)
{
    this.target = target;
    health = 2;
    turret1 = new Torret();
    eApi.addGameChild(turret1);
}

Then you can just instantiate it like this:

var ds = new desertStorm();
ds.init(ship);

// Do whatever else you need to do with your desertStorm object, e.g.:
addChild(ds);
Sly_cardinal
I havnt dragged any items from the library to the stage. all ive done and created movieclips, and linked them to the custom classes I created for them.
numerical25
A: 

Turns out that the issue is with custom classes that are attached to movieclips in the library. For some reason you cant pass arguements to classes that have movieclips from the library attached. Dont believe me ? try it out!!!

And ummm, for whoever gave me a negative, try this out

package {

    import flash.display.MovieClip;

    public class Main extends MovieClip
    {
        public function Main():void
        {
            var test:Block = new Block("test");
        }
    }
}

add the following

package com {

    import flash.display.MovieClip;

    public class Block extends MovieClip
    {
        public function Block(test:String):void
        {
            trace(test);
        }
    }
}

Then create a block movieclip and attach it to Block. make sure put Block into the com folder. When doing so you get the following

1136: Incorrect number of arguments.  Expected 0.

If you put Block into the root folder with the fla file, it should work fine.

numerical25
A: 

Not sure if this is your problem, but very often, people confuse (or simply don't know) Base Class and Class definitions in MovieCLips.

If you're using a MovieClip as your base and are exporting it for ActionScript, listen up. Some guy here thinks it's simply impossible to pass arguments through a MovieClip but it's all balls, he just doesn't know how.

So, go to your library, MovieClip > Right click > Properties

In the Export for ActionScript thingie, Notice how you've got two things, Class and Base Class.

You've got two ways to export your MovieClip for ActionScript: either you specify your class in the Base Class part and then put the name of the class in the Class part or you forgo a base class and simply use your class directly.

This is where most people fail to realize that using a base class simply makes Flash make a completely new class BASED on your class. It doesn't have anything to do with your class though, so any additional arguments or other stuff will crash.

The one most people SHOULD be taking and often don't because they simply don't know the different is the regular Class. Simply write your class path directly under the CLASS field and leave BASE CLASS completely empty.

If that's what you were doing, this should fix your problem as Flash is no longer creating its own class from your class but simply using your own class directly.

Sorry if it's not any clearer but it did fix my arguments problem.

A: 

I discovered that if you accidentially put the class file and the fla-file in different folders, a 1136 error will be shown. Make sure that the class file is found by the fla-file.

maralbjo