PDA

View Full Version : Multiple movie clips (as buttons) - same function...


maxx
07-21-2005, 09:35 PM
OK - first off, this is probably really easy, but I've searched the help files and this forum, and my wife and I just moved and I haven't even found the box with my AS books in it, let alone unpacked it, and I'm stumped...

I have a very simple function that I want to apply to every button in my movie - I'm doing a software sim right now - that sets the text of a dynamic text field to a specific value depending upon the movie clip that triggers the OnRollOver event. Of course, when the user rolls out, I've got a similar function that clears the text. Now, my problem - and question - comes in here...

I really don't want to have to type in an .onRollOver and an .onRollOut handler for each and every button throughout my movie. Is there any way that I can somehow ... group ... the buttons? For the .onRollOut at least - I realize that I may have to write separate scripts for each onRollOver just to pass the proper variable to the text field.

I thought about writing a custom class that handles this, but honestly that's something I've never played with, and I'm not sure that I can pass the variables as needed to correctly populate the text field from within a class extension (for the onRollOver triggers). That plus I really don't know how to script a class extension...

Any ideas? Or am I just stuck doing the repetitive typing? Or am I missing something extremely simple and should go stick my head in the sink to wash out the cobwebs?

xxlm
07-21-2005, 09:41 PM
you miss somthing simple :)

you can do this with a for loop, looping in the array containing your button reference
OR
you can do something like

mybutton1.onRollOut = mybutton2.onRollOut = function() {
// your code
}

maxx
07-21-2005, 09:47 PM
I knew it was something easy - thank you! Going to stick head in sink now...

Thanks again for the quick reply!

xxlm
07-22-2005, 12:14 AM
You're welcome :D

csdstudio
07-22-2005, 02:23 AM
You're welcome :D

Keep in mind you can only declare one onRelease function per btn. If you declare it again somewhere else, it overrides the first declaration. Don't know if this is your situation or not, just thought I'd warn. :D

~Rob

maxx
07-22-2005, 01:32 PM
Rob - thanks for the warning, but I always check for that first. (Only took getting burned a few times to beat that one into my head :D )