R – Linking a button to a movie clip… gotoAndPlay() doesn’t work!

actionscript-3adobeflash

I have a button, "pb".

I have a movieclip, "pm".

I want the clip to play certain frames when I press the button.

I have a layer on top of every other layer, with only one frame. In the ActionScript for that frame, I have put:

stop();

pb.addEventListener(MouseEvent.CLICK, onMouseClick);

function onMouseClick(event:MouseEvent):void 
{
    trace("I've been clicked!");
    pm.gotoAndPlay(10);
}

When I click the button, the message comes up BUT THE MOVIE DOES NOT PLAY.

What have I done wrong? This should work. I've been looking online all day and this is what everyone says to do… I'm at a loss. Thanks.

Best Answer

well the code you have there is correct for what you want to do. I guess from what you have said I would do the following:

  1. check your pm MovieClip that it does not have a stop on the frames you are playing. If it has no scripts then I guess check that it actually has enough frames for what you are doing. Maybe copy that movieclip somewhere and just let it run through.

  2. check that you don't have any other code somewhere telling it to stop playing.

  3. create another MovieClip, with 2 frames, place a stop() only on the first frame, and play it after you try to play the pm. It should play, if it does not then you need to have a look at what you are doing.

  4. lastly just make sure you created a MovieClip and did not create a button and then changed the button to a MovieClip

Related Topic