title: As3 How to flip a movieclip to face movement direction?
body: <p>Working on a maze game. When the leftkey is pressed the movieclip (char) should turn 90 degrees to the left. </p>
  
  <p>Correct me if i'm wrong but I thought I could use this code;</p>
  
  <pre><code>char.scaleX *= -1;
  </code></pre>
  
  <p>However, the most important thing is that the character doesnt go through the walls of the maze.
  And I think thats my problem for implementing the code above.
  Because it doesnt work properly when i put in here;</p>
  
  <pre><code>    if(!mazehit) {
  
                      char.y += speed;
                      char.scaleX *= -1;
  
  
                  }
  </code></pre>
  
  <p>My question to you is, where do I have to put the code to flip the movieclip?</p>
  
  <pre><code>var leftArrow, rightArrow, upArrow, downArrow:Boolean;
  var speed:Number = 4;
  var charRadius:Number = 10;
  
  stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
  stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
  stage.addEventListener(Event.ENTER_FRAME, everyFrame);
  
  function keyPressed(event:KeyboardEvent):void {
      if (event.keyCode == Keyboard.LEFT) {
          leftArrow = true;
      }
      if (event.keyCode == Keyboard.RIGHT) {
          rightArrow = true;
      }
      if (event.keyCode == Keyboard.UP) {
          upArrow = true;
      }
      if (event.keyCode == Keyboard.DOWN) {
          downArrow = true;
      }
  }
  
  function keyReleased(event:KeyboardEvent):void {
      if (event.keyCode == Keyboard.LEFT) {
          leftArrow = false;
      }
      if (event.keyCode == Keyboard.RIGHT) {
          rightArrow = false;
      }
      if (event.keyCode == Keyboard.UP) {
          upArrow = false;
      }
      if (event.keyCode == Keyboard.DOWN) {
          downArrow = false;
      }
  }
  
  function everyFrame(event:Event):void {
      var mazehit:Boolean = false;
      if (leftArrow) {
          for(var i:int = 0; i &lt; speed; i++) {
              if(bounds.hitTestPoint(char.x - charRadius - i, char.y, true)) {
  
  
                  mazehit = true;
                  break;
              }
          }
          if(!mazehit) {
  
              char.x -= speed;
  
  
  
  
          }
  
      } else if (rightArrow) {
          for(var j:int = 0; j &lt; speed; j++) {
              if(bounds.hitTestPoint(char.x + charRadius + j, char.y, true)) {
  
                  mazehit = true;
                  break;
              }
          }
          if(!mazehit) {
  
              char.x += speed;
          }
      } else if (upArrow) {
          for(var k:int = 0; k &lt; speed; k++) {
              if(bounds.hitTestPoint(char.x, char.y - charRadius - k, true)) {
  
                  mazehit = true;
                  break;
              }
          }
          if(!mazehit) {
              char.y -= speed;
          }
  
      } else if (downArrow) {
  
          for(var m:int = 0; m &lt; speed; m++) {
              if(bounds.hitTestPoint(char.x, char.y + charRadius + m, true)) {
  
                  mazehit = true;
                  break;
              }
          }
          if(!mazehit) {
  
              char.y += speed;
  
  
          }
      }
  }
  </code></pre>
  
  <p>thank you for your time</p>