Search code examples
actionscript-3animationtween

AS 3 simple ease


How can I move an object and be able to physically see it when it is moving? Not just disappear and appear on a different location like it would be using the following code.

buttonL2_btn.addEventListener(MouseEvent.CLICK, left);

function left(event:Event):void{

      box_mc.x =241.5;
}

This is going to move myObject to any location specified, but again I want to be able to see it when moving.


Solution

  • In your example you are just setting it's X position when some button is pressed, when you need to change X into an EnterFrame event, like this:

    this.addEventListener(Event.ENTER_FRAME, move);
    
    function move(event:Event):void{
          box_mc.x -= 5
    }
    

    Your box_mc should move left 5 pixels accordingly with your framerate.


    You can use a easing library to that easily. I strongly recommend TweenMax.