Search code examples
flashactionscript-3buttonmouseeventtimeline

How do I play movie clip when you click on button


I am new to flash....Here's what I am trying to do. I working on the timeline and have some Actionscript 3 code (I have a actions layer on the timeline). I am not sure what the code is for clicking on a button(I made the buttons movie clips since I wanted to animate it) and it plays a movie clip. Any help would be appreciated! Thanks


Solution

  • Assuming you have one button (movieclip) named "myButton" and one movieclip named "targetMc" on stage you can do it like this:

    myButton.buttonMode = true; // set the movieclip to act as a button
    myButton.addEventListener(MouseEvent.CLICK, onButtonClick); // add mouse listener
    
    function onButtonClick(event : Event) : void
    {
        trace("clicked" + event.target);
        //gotoAndPlay("someFrameLabel"); // plays frame in current timeline
        targetMc.gotoAndPlay("someFrameLabel"); // plays frame in instance "targetMc" timeline
    }