Hello, welcome to the community
A quick look shows that the problem is here:
currentMap = maps[currentMapIndex];
level = new Level(currentMap.xml);
currentMap is being set to null because the currentMapIndex is 2, which is out of the range of the maps[] array (it contains 2 entries at this point, which would be accessed using a map index of 0 or 1). When it tries to do the currentMap.xml part, it can’t because currentMap is null. You probably want to check for this condition and handle it appropriately;
if(currentMap != null)
{
level = new Level(currentMap.xml);
}
else //do something
However, the more important thing is why currentMapIndex is being set to 2.
It seems as if this function is being called every frame:
public function switchMap():Boolean {
//check where the players have to go
var direction:int = checkMapBoundaries();
if (direction != NONE) {
switch(currentMap.Lname) {
case("level 1"):
if (direction == LEFT) {
currentMapIndex = 1;
return true;
}
break;
case("level 2"):
if (direction == RIGHT) {
currentMapIndex = 2;
return true;
}
break;
}
}
return false;
}
and direction always seems to be coming out as 2, even when I am well within the bounds of the level. In FlashDevelop, if you click in the column to the left of your line numbers (it looks like a little white column gap thingy) it’ll put a little red dot. This is called a breakpoint; when you run the game, your debugging will pause if the code ‘hits’ that breakpoint at any time. So if you put a breakpoint on the “switch(currentMap.Lname) {” line, you can see if your code reaches it and investigate the state of all the variables at the time it does so. It seems to be getting to that point every single frame, with a direction of 2, which leads me to believe that your checkMapBoundaries function has a bug. The ultimate result of this is that the currentMapIndex gets set to 2 every single frame.
It’s time for bed though so that’s all I can do for now!