Newbie actionscript animation control question

Hi,

I’m trying to control coded animations with buttons, here is my stripped down code:

// Animation code:

function anim1() {
// looping animation code here
}

function anim2() {
// looping animation code here
}

function anim3() {
// looping animation code here
}

// Button code:

button1_btn.onRelease = function() {
anim1();
};

button2_btn.onRelease = function() {
anim2();
};

button3_btn.onRelease = function() {
anim3();
};

When I press button1_btn, each press starts a new anim1 function. When I press button2_btn, anim1 still loops, but now anim2 plays at the same time. What I really want is for each button1_btn press, to cancel any previous anim1 function, and then start a new anim1. Likewise, if I press button2_btn, it should cancel any previous running animations, then start a new anim2. I hope I’m not confusing, not sure how to explain it, but essentially I’m trying to start and stop three coded animations with three buttons.

Thanks,

rm