Is it possible to animate buttons in AS3?

Hello everyone,

I’m new to AS3 and so far it has been going quite well because I was able to get much out of tutorials, but now I am stuck with a problem.
I am making a website and I want to animate a button (buttonA), after a certain button (buttonB) is clicked buttonA should move from underneath buttonB and should move to a certain location (it only moves vertically). The movement should slow down a bit when the button reaches it’s destination to make the movement look smooth.
When buttonA is pressed some other action should be done and buttonA should only be able to get pressed when it reached it’s destination below buttonB
And lastly, when ButtonB is pressed when buttonA has reached it destination nothing should happen. And when some other button which is already on the screen (buttonC) is pressed buttonA should be returned to it’s original position (after which buttonB can be pressed again to move buttonA)

The current way I am doing it is so: on frame 1 ButtonA is positioned underneath buttonB. Both buttons are on different layers. A new layer (“actions”) has this code:

stop();

buttonB.addEventListener(MouseEvent.CLICK, clickButtonB);

function clickButtonB(event:MouseEvent):void
{
    gotoAndPlay(2);
}

On frame 2 the actions layer has a new blank keyframe with this code:





 addEventListener(Event.ENTER_FRAME, moveButton);
  
  function moveButton(event:Event):void {
      buttonA.y += slowDown(buttonA.y, 268.35, 8);
     );
}

function slowDown(begin:Number, end:Number, speed:Number):
  Number {    return (end-begin)/speed;}
}
  stop();

When I play it it goes well for the first time, but when I press buttonB afterwards it looks like it goes through all the frames after frame 1&2, then it returns to frame 1 and the position of buttonA is reset and buttonA starts moving to its destination again. I also get this in my output:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at showcase17_fla::MainTimeline/moveButtons()

Does anyone know how I can fix this or how I can achieve what I want to achieve. I have tried countless things but I just can’t seem to fix it. Help is very much appreciated!

(Buttons A,B and C are of type:Button)