1

I asked a question the other day and it taught me a fair bit about display objects and stuff. I have another problem though.

This is my document class :

package 
{

    import flash.display.MovieClip;
    import flash.display.Stage;

    public class Engine extends MovieClip
    {

        public function Engine()
        {
            var calling:Callitems = new Callitems(cat, BluKnife)

            stage.addChild(calling);

        }

    }

}

cat and BluKnife are movieclips in my library with as3 linkage to those names.

Now here is the Callitems Class

package 
{

    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.display.InteractiveObject;


    public class Callitems extends MovieClip{


    public function Callitems(Enemy1, Enemy2)
    {
        var knife:Enemy1 = new Enemy1();

        this.addChild(knife);
        knife.x = 200;


        var ct:Enemy2 = new Enemy2();

        this.addChild(ct);


    }

}

}

Now my problem is that when I wasn't giving Callitems arguments and was instead just making Enemy1, cat and making Enemy2, Bluknife both of those movieclips were added to the stage as expected. But now that I'm trying to make Callitems take arguments so that I can place different clips at certain times I'm getting the following error:

1046: Type was not found or was not a compile-time constant: Enemy1. 1046: Type was not found or was not a compile-time constant: Enemy2.

Thanks everyone, any help is much appreciated

Edit: I did search this site for that same error, but I don't understand the problem in this context, sorry!

Mark D
  • 75
  • 1
  • 7

2 Answers2

2

The problem is that Enemy1 is not recognized by the compiler as a type (since it is a variable name) when you define var knife:Enemy1. Try just casting it as a more general type:

var knife:MovieClip = new Enemy1() as MovieClip;
Kodiak
  • 5,978
  • 17
  • 35
  • You're welcome, but read @mossefetcher's answer as weel. You should also specify a type for your constructor's parameters. And you should also use lower-case variables (knife, type1) and upper-case classes (Cat, BlueKnife). – Kodiak May 10 '13 at 14:30
  • Ahh yes, noted. Yeah I tried this solution in conjunction with mossefetcher's but I was getting the same answer. Maybe I was doing it wrong. Do you mean specifying the type as in Enemy:MovieClip? Instead of just letting it use the default 'object' type? – Mark D May 10 '13 at 14:40
  • Yes, sorry I meant `public function Callitems(type1:Class, type2:Class)` – Kodiak May 10 '13 at 14:44
  • And then `var knife:MovieClip = new type1() as MovieClip` – Kodiak May 10 '13 at 14:44
1

The problem is you seem to have class names as the parameters for the Callitems constructor. It should read something like:

public function Callitems(parameter1:Enemy1, parameter2:Enemy2)
    {...

You are also passing undefined variables to the Callitems constructor (cat and BluKnife). If they're supposed to be passed into Callitems (which is, perhaps, not a great idea), they should at least be defined first.

moosefetcher
  • 1,841
  • 2
  • 23
  • 39
  • Thanks also! Sorry I understand what you mean now too, I'll work on using better practices. – Mark D May 10 '13 at 14:41