0

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?

1 Answer 1

2

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; 
Sign up to request clarification or add additional context in comments.

4 Comments

Or simply var lvlmapping:*;.
Nice catch! I'll accept it tomorrow since I have to wait for a long time now, you were too fast ;)
Actually, in my case, things still crashed when doing a collision detection. That problem was solved by using MovieClip instead. Thanks again!
He answered correctly, that's a different issue. Your collision detection likely required a MovieClip method, but that's a separate issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.