Flash CS4: How to play a movie clip when a button is clicked

actionscript-3adobebuttonflashmovieclip

I want to play a movie clip when I click a button.

I made 3 states:

inicial (how it looks before anything happens) (up)
hover (plays an animation after waiting 20 frames) (over)
click (plays an animation right away) (down)

I placed these movie clips inside of my button's up, over, and down frames. This works great except when I click, i'll need to click and hold for my animation to get past the first frame.

What can I do so that I click on my button and plays the movie clip in its entirety?

Best Answer

Assuming you're creating a button in the IDE: Because the button "down" state is only registered while its actually "down", you'd need to associate a movieclip outside of the button that is triggered on mouse down.

someButton.addEventListener(MouseEvent.MOUSE_DOWN, runClip);

private function runClip(e:MouseEvent):void
{
    _downClip.play();
}

You'd need to position it accurately, or wrap it up in another symbol.

...

Or better yet, program the whole thing in AS3 and get away from timeline development...

update -

I don't have any preferred tutorials or sites for this, in particular. But just google "as3 button tutorial" and you should get a lot of hits... this one looks pretty complete.

Oh, wait - I think I posted a class for a basic image button that could be easily altered to function with movieclips from the library... yep, its right here. The basic idea should be fairly clear if you have any experience with as3 / object oriented programming. And if its not - google away ;)

Cheers

Related Topic