Skip to main content
Participant
August 2, 2007
Answered

Arrays & MovieClip Buttons

  • August 2, 2007
  • 7 replies
  • 358 views
I have a scene that has 10 buttons that I would like to have the following behavior:

1. onRollOver, button border highlights
2. onRollOut, button returns to default appearance
3. onRelease, button text bolds and remains that way until another button is pressed
4. With an onRelease event, I would also like to set a single variable to an integer. This will be input for a second animation sequence.

And I want the first button to start out as if it were already pressed.

I have built this with an Array of MovieClip buttons. Each movieclip has _up, _over, _down states. I've used an Array to eliminate the need to copy the same event handling code 10 times.

I have behaviors #1 & 2 finished. However, behaviors #3 & 4 are giving me a headache. I can get the "_down" state to stick only as long as I don't RollOver any other button. In addition, I can't get the variable ("pressed") to take any value other than 10 (which is clearly the end of the for loop).

Any recommendations on how to proceed, or how to do this more elegantly, would be greatly appreciated.

Here's the relevant code:

This topic has been closed for replies.
Correct answer _name
i came with this script a while back and use it just about every site i make.

7 replies

Inspiring
August 2, 2007
i attached an example to the thread by editing my last post. take a look.
Participant
August 2, 2007
Yes. I now realize a little string processing will take care of that, right?

I'm also realizing that I could allow any old value between 0 and 1, not just 10 decimals. So I could just as easily build a slider as a control. Hmmm... funny how the brain latches onto one idea and doesn't let go until shaken hard.

Thanks again for the help!
Inspiring
August 2, 2007
i think you could accomplish it. your going to have to something like:
Participant
August 2, 2007
OK, thanks for the code. I'll take a look at it.

I'm excited about your suggestion of using the instance name for the button text. But I think I'll have a problem.

My project is an astronomy demo, and I want to label the buttons with text like:

"e = 0.1" (for the eccentricity of a planetary orbit, if you're curious) Even without the "e =" part, I still want to label the buttons with numbers.

Do you see a way to use this text as an instance name anyway, or am I stuck creating individual text labels?

Thanks again for your timely assistance.
Inspiring
August 2, 2007
check now.
by the way, when you are using ten buttons it is best to make only one button and keep reusing it. be sure to label all of your animation states within your button and use my code to call them at their appropriate times (i.e. onRollOver / onRollOut/ onRelease). if you have dynamic text inside your button instance and you want it to read differently for each button just add this to the for loop (make sure your instance name reads as you want your text to appear in the button - ex. you want your button to say "HOME" then make its instance name "HOME"):
Participant
August 2, 2007
_name, I'm intrigued by your answer, but don't see a script or URL in your post.
_nameCorrect answer
Inspiring
August 2, 2007
i came with this script a while back and use it just about every site i make.