Combining tony pa tutorials

I’ve been trying to combine two of the tutorials on tony pa’s website to get a mouse controlled sprite and the change map function working.

Mouse tutorial:
http://www.tonypa.pri.ee/tbw/tut17.html

Map change tutorial:
http://www.tonypa.pri.ee/tbw/tut06.html

I have all the functions in the code but where I’m having trouble is actually getting the map to change when the door tile is walked onto.

I have tried this rather crude way of adding the change map function to each if statement in the move character function - but this is only chnaging the map once the character moves off that tile rather than onto it.


function moveChar(ob) {
  if((ob.x-game.tileW/2)%game.tileW==0 and (ob.y-game.tileH/2)%game.tileH==0){
	ob.xtile = Math.floor(ob.x/game.tileW);
	ob.ytile = Math.floor(ob.y/game.tileH);
	if(game["t_"+ob.ytile+"_"+(ob.xtile+1)].walkable and game.targetx>ob.xtile){
	  ob.dirx=1;
	  ob.diry=0;
	  if (game["t_"+ob.ytile+"_"+ob.xtile].door and ob == _root.char) {
		// make new map
		changeMap(ob);
		ob.moving=false;
	}
	}else if(game["t_"+ob.ytile+"_"+(ob.xtile-1)].walkable and game.targetx<ob.xtile )="">
	  ob.dirx=-1;
	  ob.diry=0;
	  if (game["t_"+ob.ytile+"_"+ob.xtile].door and ob == _root.char) {
		// make new map
		changeMap(ob);
		ob.moving=false;
	}
	}else if(game["t_"+(ob.ytile+1)+"_"+ob.xtile].walkable and game.targety>ob.ytile){
	  ob.dirx=0;
	  ob.diry=1;
	  if (game["t_"+ob.ytile+"_"+ob.xtile].door and ob == _root.char) {
		// make new map
		changeMap(ob);
		ob.moving=false;
	}
	}else if(game["t_"+(ob.ytile-1)+"_"+ob.xtile].walkable and game.targety<ob.ytile )="">
	  ob.dirx=0;
	  ob.diry=-1;
	  if (game["t_"+ob.ytile+"_"+ob.xtile].door and ob == _root.char) {
		// make new map
		changeMap(ob);
		ob.moving=false;
	}
	}else{
	  ob.moving=false;
	  return;
	}
  }

I realise I am probably doing something drastically wrong here as my AS isnt too hot! But if anyone is familiar with these tutorials and who can see the problem any help would be much much appreciated!

Thanks
</ob.ytile></ob.xtile>