AS3 Using a variable inside removeChild to remove currentLevel

I have a string variable that identifies the current level, this is placed in the timeline when it reaches this level.

var currentLevel:String = "level1";

I have a dispatch event that is called when end of the level has been reached.

dispatchEvent(new Event("levelend", true));

I have put this into document class:

function proceedLevel(event:Event):void
        removeEventListener("levelend", proceedLevel);

Each level is called like this:

var level1:Level1 = new Level1();
level1.x = 0;
level1.y = 0;

Each level is in its own Movieclip but when it reaches the end of the timeline in that movieclip it dispatches the event "levelEnd". the document class listens and then attempts to remove the instance calling removeChild. I add the string currentLevel and place it into removeChild to hopefully try and get rid of it from the document class.

I get this error:

implicit coercion of a value of type to an unrelated type flash display    displayobject

I know it is not happy about the string being passed into the removeChild!



You can add another variable var currentLevelView:DisplayObject set it after creating level display object and use it in removeChild or you can set the = currentLevel and change removeChild to removeChild(getChildByName(currentLevel))

Need Your Help

Inputting a character from the keyboard in C

c char

I have the following piece of code where check is for char type