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);
SoundMixer.stopAll();
removeChild(currentLevel);
gotoAndStop(nextScene);
}
Each level is called like this:
var level1:Level1 = new Level1();
level1.x = 0;
level1.y = 0;
addChild(level1);
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!
Thanks
You can add another variable
var currentLevelView:DisplayObjectset it after creating level display object and use it inremoveChildor you can set thelevel1.name = currentLeveland changeremoveChildtoremoveChild(getChildByName(currentLevel))