Strange collision behaviour

I am trying to make a tile based game its based on the tony pa tutorials, it mostly works but occasionally the char Object sticks to the wall and occasionally will go straight through the tile object. I was wondering if someone could tell me where Im going wrong or at least point me in the right direction.


package  {
	
	import flash.display.MovieClip;
	import flashx.textLayout.utils.CharacterUtil;
	import flash.events.*;
	
	public class Main extends MovieClip {
		public var mapHeight:Number;
		public var mapWidth:Number;
		public var newTile:Tile;
		public var newGround:Ground;
		public var char:Char;
		public var map = [
						 [1,1,1,1,1,1,1,1,1,1,1,1],
						 [1,0,0,0,0,0,0,0,0,0,1,1],
						 [1,0,1,0,1,0,0,0,0,0,0,1],
						 [1,0,0,0,0,0,0,1,0,1,0,1],
						 [1,0,0,0,0,0,0,0,0,0,0,1],
						 [1,1,1,1,1,1,1,1,1,1,1,1],
						 ];
		
		public function Main() {
			// constructor code
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            
			buildMap();
		}
		private function keyDownHandler(event:KeyboardEvent):void {
			if(event.keyCode==40){
					moveChar(0, 1);
				}
			if(event.keyCode==38){
					moveChar(0, -1);
				}
			if(event.keyCode==37){
					moveChar(-1, 0);
				}
			if(event.keyCode==39){
					moveChar(1, 0);
				}
		}
		
		public function buildMap():void{
			mapHeight = map.length;
			mapWidth = map[0].length;
			//trace(map);
			for(var i:Number = 0; i<mapHeight; i++){
				for(var j:Number = 0; j<mapWidth; j++){
					if(map*[j]==1){
						newTile= new Tile();
						newTile.name = "tile"+i+j;
						addChild(newTile);
						newTile.walkable = false;
						newTile.x = 15+(j*30);
						newTile.y = 15+(i*30);
					}
					if(map*[j]==0){
						newGround = new Ground();
						newGround.name = "tile"+i+j;
						addChild(newGround);
						newGround.walkable = true;
						newGround.x = 15+(j*30);
						newGround.y = 15+(i*30);
					}
				}
			}
			char = new Char();
			addChild(char);
			char.x = 45;
			char.y = 45;
		}
		function getMyCorners():void{
				char.downY=Math.floor((char.y+(char.height/2)+3)/30);
				char.upY = Math.floor((char.y-(char.height/2)-3)/30);
				char.leftX = Math.floor((char.x-(char.width/2)-3)/30);
				char.rightX = Math.floor((char.x+(char.width/2)+3)/30);
		}
		public function moveChar(dirX:Number, dirY:Number){
			getMyCorners();
			if(dirX ==-1){
				var leftTopTile = getChildByName("tile"+char.upY+char.leftX);
				var leftBottomTile = getChildByName("tile"+char.downY+char.leftX);
				if(leftTopTile.walkable == true && leftBottomTile.walkable == true){
					char.x+=dirX*3
					trace("MOVE LEFT");
				}
			}
			if(dirX == 1){
				var rightTopTile = getChildByName("tile"+char.upY+char.rightX);
				var rightBottomTile = getChildByName("tile"+char.downY+char.rightX);
				if(rightTopTile.walkable == true && rightBottomTile.walkable == true){
					char.x+=dirX*3
					trace("MOVE Right");
					}		
			}
			if(dirY == -1){
				var leftTopTile2 = getChildByName("tile"+char.upY+char.leftX);
				var rightTopTile2 = getChildByName("tile"+char.upY+char.rightX);
				if(leftTopTile2.walkable == true && rightTopTile2.walkable == true){
					char.y+=dirY*3
					trace("MOVE UP");
					}		
			}
			if(dirY == 1){
				var rightTopTile3 = getChildByName("tile"+char.upY+char.rightX);
				var rightBottomTile3 = getChildByName("tile"+char.downY+char.rightX);
				if(rightTopTile3.walkable == true && rightBottomTile3.walkable == true){
					char.y+=dirY*3
					trace("MOVE UP");
					}		
			}
		}
	}
}