Joetjah
Joetjah

Reputation: 6132

Adding a variable object

I'm trying to add an object based on the level number. I've got the following declaration:

var lvlmapping:Object;

Later on, I run the following code:

if (levelnr == 1)
    lvlmapping= new lvl1map();
if (levelnr == 2)
    lvlmapping= new lvl2map();
if (levelnr == 3)
    lvlmapping= new lvl3map();
lvlmapping.x = 0;
lvlmapping.y = 0;
this.addChild(lvlmapping);
trace("Added mapping");

The following error pops up:

Implicit coercion of a value of type static Object to a possible unrelated type flash.display:DisplayObject

What can I do to achieve what I want?

Upvotes: 0

Views: 40

Answers (1)

Barış Uşaklı
Barış Uşaklı

Reputation: 13532

If lvl1map and the others are assets you will need to use DisplayObject,Sprite or MovieClip and not Object. So try changing :

var lvlmapping:Object;

to :

var lvlmapping:DisplayObject; 

Upvotes: 2

Related Questions