Hi, so I cannot for the life of me figure out what im doing wrong… its quite a long code, but it looks the same to me. for some reason I can move ‘hero’ upwards, but i cannot move left, right or down, even though the coding looks legit (to me). Here it is:
stage.focus = this;
stage.addEventListener(KeyboardEvent.KEY_DOWN , moveHero);
function moveHero( evt:KeyboardEvent ) : void
{
if ( evt.keyCode == Keyboard.UP )
{
hero.y -= 10;//moves up
hero.scaleY=1;
hero.gotoAndStop(‘walking2’);//plays animation walking up
if(currentLabel == "town6")
{
gotoAndStop("wharf1");//changing screens
hero.y = 600;//where he spawns
for(var u = 0; u<townWalls6.length; u++)//loop
{
if(hero.hitTestObject(townWalls6[u]))//cannot pass through walls
{
hero.y+=10;//stops walking
}
}
}
if(currentLabel == "town5")
{
gotoAndStop("town6");
hero.y = 600;
for(var v = 0; v<townWalls5.length; v++)
{
if(hero.hitTestObject(townWalls5[v]))
{
hero.y+=10;
}
}
}
else if ( evt.keyCode == Keyboard.DOWN )
{
hero.y += 10;
hero.scaleY=1;
hero.gotoAndStop('walking2');
if (currentLabel == "wharf1" && hero.y < 0)
{
gotoAndStop("town6");
hero.y = 600;
for(var w = 0; w<townWalls7.length; w++)
{
if(hero.hitTestObject(townWalls7[w]))
{
hero.y+=10;
}
}
}
if (currentLabel == "town6" && hero.y < 0)
{
gotoAndStop("town5");
hero.y = 600;
for(var xx = 0; xx<townWalls6.length; xx++)
{
if(hero.hitTestObject(townWalls6[xx]))
{
hero.y+=10;
}
}
}
else if ( evt.keyCode == Keyboard.LEFT )
{
hero.x -= 10;
hero.scaleX=1;
hero.gotoAndStop(‘walking’);
if (currentLabel == "town2" && hero.x < 0)
{
gotoAndStop("town1");
hero.x = 800;
for(var e = 0; e<townWalls2.width; e++)
{
if(hero.hitTestObject(townWalls2[e]))
{
hero.x-=10;
}
}
}
if (currentLabel == "town3" && hero.x < 0)
{
gotoAndStop("town2");
hero.x = 800;
for(var f = 0; f<townWalls3.width; f++)
{
if(hero.hitTestObject(townWalls3[f]))
{
hero.x-=10;
}
}
}
else if ( evt.keyCode == Keyboard.RIGHT )
{
hero.x += 10;
hero.scaleX=-1;
hero.gotoAndStop(‘walking’);
if (currentLabel == "town1" && hero.x > 800)
{
gotoAndStop("town2");
hero.x = 0;
for(var yyy = 0; yyy<townWalls.width; yyy++)
{
if(hero.hitTestObject(townWalls[yyy]))
{
hero.x-=10;
}
}
}
if (currentLabel == "town2" && hero.x > 800)
{
gotoAndStop("town3");
hero.x = 0;
for(var zzz = 0; zzz<townWalls2.width; zzz++)
{
if(hero.hitTestObject(townWalls2[zzz]))
{
hero.x-=10;
}
}
}
The code is muuuuuch longer than this, but this is just an example.