# Newbie actionscript animation control question

**URL:** <https://forum.kirupa.com/t/newbie-actionscript-animation-control-question/255034>\
**Category:** Uncategorized\
**Created:** [March 18, 2008, 1:29pm UTC](https://forum.kirupa.com/t/newbie-actionscript-animation-control-question/255034 "2008-03-18T13:29:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rooterman42](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rooterman42](https://forum.kirupa.com/u/rooterman42)\
**Post date:** [March 18, 2008, 1:29pm UTC](https://forum.kirupa.com/t/newbie-actionscript-animation-control-question/255034/1 "2008-03-18T13:29:15Z")

</div>

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
