Getting Names from Arrayed Buttons
I'm a fresh convert from AS2 to AS3, and I'm beginning to suspect my previous experience isn't going to help me at all. I'm making a very simple app, just ten buttons, all with similar names, and I'm using a for loop to do them all at once. So far so good, as far as I can tell. My problem comes when I try to identify which button was clicked.
Here's my code so far:
The result of which is that every button returns "dice10." I feel like if I could just get this working the rest would fall into place.
Also is there any website or forum you guys would recommend for people moving from AS2 to AS3?
your 'for' loop is starting at (var i =1) and ending at (var i=10), changing curClick each time.
the last time it sets curClick to be 'dice10', so that is what it will remain until it is further changed, which clicking on a button will not do with your code.
what i believe you want to do is to return ( trace out) the instance name of the button that is clicked. so it can be done by asking for the event target's name, usually done like this:
event.target.name or the way i prefer e.target.name
since you use the custom event name '$event', your onClick function would work like this:
so basically your variable curClick was useless as it was fixed at 'dice10' with no means to change.
a possible way to make it useful for some other situations is to not declare it in the 'for' loop, but in the 'onClick' function to declare it as such:
then you would have a record of the last button clicked, which could be useful in some situations.
i hope that helps. switching from AS2 to AS3 is a little bit of an old subject right now, so the forums for that have died down. pick up a good beginning book on AS3. if you have a good handle on AS2, it should go pretty quick for you.
if you want to see this in action, consider this complete set of working code, for 10 movieclip symbols on the stage with names 'dice1' through 'dice10'
this is an example based on your initial code, for something that i get asked about all the time, that of making 'sticky' buttons to show which button was the last one clicked. that is one situation where this variable 'curClick' would come in useful:
i hope this helps further