4 Replies Latest reply on May 28, 2015 8:42 AM by azkianury

    How to limit movieclip movements on stage?

    azkianury

      Hi, I want to move my movieclip to the left and right but it keeps moving out of the stage. I want to limit the X movement to the width of my stage.

       

      This is my code for the movieclip movement:

       

      import flash.events.KeyboardEvent;

      stage.addEventListener(KeyboardEvent.KEY_DOWN, moveavatar);

      function moveavatar (event:KeyboardEvent):void

      {

        if (event.keyCode == 39)

        {

        avatarmove.x += 10;

        }

        else if (event.keyCode == 37)

        {

        avatarmove.x -= 10;

        }

      }

       

      How do I limit the X movement to the width of my stage so it won't move out of stage? Thank you.