This content has been marked as final. Show 6 replies
I don't know any way. If anybody else has suggestions…
However, a ton of onRelease functions isn't generally a problem – if you name or attach your buttons sensibly.
That attaches 100 buttons to the stage (or where ever this is) and will have them trace their name.
Yikes, that's lean code. *laughs* And way over my head. I don't have much experience creating and programming objects on the fly using code and for loops. I can understand most of the syntax, but not too sure what everything does. It's only a couple of dozen buttons, I think I should probably stick to manually coding the onRelease. I was just checking if I was missing something (relatively) simple.
Thanks a lot for your help, and I've filed that nifty function you wrote in that other thread away. Looks very handy.
Really. This is worth learning. Even if you just have your buttons put on the stage manually during author time. In that case give each one an instance name like, button0, button1, etc. (Dont' start with the numbers, end the names with them.) And let's say you have 12 of them. Then use this:
That says numButtons equals 12.
For all the values of i starting at zero adding one to i each time until it is no longer less than numButtons do the following. (Remember that we started with zero so if there are 12 buttons the biggest number will be button11! Why is it so hard to start counting at zero?)
Make a variable called curButton that will look inside this object (the current scope) and look for something that has the name of "button" plus whatever value i currently has. PS: This is expecting that your buttons are acutally MovieClips with button like behaviours, not actual buttons.
Take that curButton and apply an onRelease event handler to it.
Inside that even handler notice that instead of saying trace(curButton) we say trace(this). That is because we have changed the scope by applying the onRelease to a specific instance.
This is a technique you will use over and over and over again. If you plan to do much with AS it will be a very useful thing to learn NOW, not LATER! :)
Wow, a free lesson! :D That makes perfect sense to me now; I didn't realize you could program functions repetitively like that, and the scope was messing me up. Thanks a ton, I really appreciate you going the extra mile. I realize now how needlessly repetitive my code is. @_@
Sure glad to help you out. This really will serve you well.
Here is a little exercise for you. Get it to trace the number. So for example button0 will trace "0" and button7 will trace "7".