ForumsProgramming ForumButtons....why do you annoy me so?

6 3573
kingryan
offline
kingryan
4,196 posts
Farmer

Hi,

I'm using CS3 on a trial and can't work out how to make buttons work.

I can get it so that they do different things (i.e change colour) when are moused over or clicked, however I can't work out the code to make it the movie play.

Using AS3.

Thanks!

  • 6 Replies
kingryan
offline
kingryan
4,196 posts
Farmer

So I found this, which seems to work ok...

stop()
button.addEventListener(MouseEvent.CLICK, playFirst);



function playFirst(e:MouseEvent):void {

gotoAndPlay(2);

}


Is that the best code to use or is there a simpler one?
PixelSmash
offline
PixelSmash
566 posts
Nomad

Pretty much, yeah. You might want to switch the gotoAndPlay with a regular play(), but then again - there's no real need for it. This is as short as it gets in AS3!

Voidcrystal
offline
Voidcrystal
138 posts
Nomad

isn't it like in AS2? on (press) {gotoAndPlay(frame);{
}

Marcellino
offline
Marcellino
5 posts
Nomad

If you're using AS3, you need to add an Event Listener to the Button. Give your button an instance name and then use the code

myButtonName.addEventListener(MouseEvent.CLICK, myButtonFunction);

replacing myButtonName and myButtonFunction with whatever you'd like to call them. This tells Flash that whenever the button is clicked, it will perform the actions found in the designated function.

rjbman
offline
rjbman
215 posts
Nomad

That's just fine. Your code should work.

Darkroot
offline
Darkroot
2,763 posts
Peasant

It's not going to be very flash garbage collection friendly but it's as simple as it gets.

Showing 1-6 of 6