Skip to main content
Inspiring
October 15, 2009
Answered

Help on a basic script

  • October 15, 2009
  • 2 replies
  • 797 views

How do I use gotoAndPlay comand with multipal buttons.

WORKS:

AA.addEventListener(MouseEvent.CLICK, release);
function release(evt:MouseEvent):void {
gotoAndPlay(5);
}

DOESN'T WORK:

AA.addEventListener(MouseEvent.CLICK, release);
function release(evt:MouseEvent):void {
gotoAndPlay(5);
}

BB.addEventListener(MouseEvent.CLICK, release);
function release(evt:MouseEvent):void {
gotoAndPlay(10);
}

Thanks!

This topic has been closed for replies.
Correct answer Ned Murphy

You cannot duplicate function names, so one solution would be...

AA.addEventListener(MouseEvent.CLICK, releaseAA);
function releaseAA(evt:MouseEvent):void {
gotoAndPlay(5);
}

BB.addEventListener(MouseEvent.CLICK, releaseBB);
function releaseBB(evt:MouseEvent):void {
gotoAndPlay(10);
}

2 replies

Inspiring
October 16, 2009

If you have a lot of buttons, you might consider switching on the button's name. Something like the following:

AA.addEventListener(MouseEvent.CLICK, release);
BB.addEventListener(MouseEvent.CLICK, release);
function release(evt:MouseEvent):void {
    switch(evt.target.name){
        case "AA":
            gotoAndPlay(5);
            break;
        case "BB":
            gotoAndPlay(10);
            break;
        default:
    }
}

Ned Murphy
Ned MurphyCorrect answer
Legend
October 15, 2009

You cannot duplicate function names, so one solution would be...

AA.addEventListener(MouseEvent.CLICK, releaseAA);
function releaseAA(evt:MouseEvent):void {
gotoAndPlay(5);
}

BB.addEventListener(MouseEvent.CLICK, releaseBB);
function releaseBB(evt:MouseEvent):void {
gotoAndPlay(10);
}

Inspiring
October 15, 2009

Thanks Sir!! 

Ned Murphy
Legend
October 16, 2009

You're welcome