# Optimizing As3 Button Code

**URL:** <https://forum.kirupa.com/t/optimizing-as3-button-code/312444>\
**Category:** flash\
**Created:** [August 3, 2010, 5:20pm UTC](https://forum.kirupa.com/t/optimizing-as3-button-code/312444 "2010-08-03T17:20:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichDesigner](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@RichDesigner](https://forum.kirupa.com/u/RichDesigner)\
**Post date:** [August 3, 2010, 5:20pm UTC](https://forum.kirupa.com/t/optimizing-as3-button-code/312444/1 "2010-08-03T17:20:55Z")

</div>

Hello, how are you all?

Well, this is my first post… so im going to pop that cherry.  
I am new to Actionscript, so im jumping directly into AS3. I have a book handy but have noticed, that they really dont include best and optimal practices.

i have 8 buttons, all doing the same thing. my code comes out to something like this…

```auto

function moveSelector1(event:MouseEvent) {
    this.animSequence.gotoAndStop(1);
}
function moveSelector2(event:MouseEvent) {
    this.animSequence.gotoAndStop(2);
}
function moveSelector3(event:MouseEvent) {
    this.animSequence.gotoAndStop(3);
}
function moveSelector4(event:MouseEvent) {
    this.animSequence.gotoAndStop(4);
}
function moveSelector5(event:MouseEvent) {
    this.animSequence.gotoAndStop(5);
}
function moveSelector6(event:MouseEvent) {
    this.animSequence.gotoAndStop(6);
}
function moveSelector7(event:MouseEvent) {
    this.animSequence.gotoAndStop(7);
}
function moveSelector8(event:MouseEvent) {
    this.animSequence.gotoAndStop(8);
}
animSequence.stripclub.hit1.addEventListener(MouseEvent.CLICK, moveSelector1)
animSequence.stripclub.hit2.addEventListener(MouseEvent.CLICK, moveSelector2)
animSequence.stripclub.hit3.addEventListener(MouseEvent.CLICK, moveSelector3)
animSequence.stripclub.hit4.addEventListener(MouseEvent.CLICK, moveSelector4)
animSequence.stripclub.hit5.addEventListener(MouseEvent.CLICK, moveSelector5)
animSequence.stripclub.hit6.addEventListener(MouseEvent.CLICK, moveSelector6)
animSequence.stripclub.hit7.addEventListener(MouseEvent.CLICK, moveSelector7)
animSequence.stripclub.hit8.addEventListener(MouseEvent.CLICK, moveSelector8)

```

Is there any way to optimize this code? You dont have to do it for me, id just like to know the overall concept.

thanks, and the moment i become an expert , i look forward to helping others just like me…

Thanks,

Richard:hoser:
