Organizing buttons so that they arrange 'automatically'
Hey there,
I've got about 40 buttons set up in three columns, with the text content of the buttons being imported from a txt file and the button symbols overlaying the matching text.
Check out the attached file for an example set up.
The txt file also contains the section headers which divide the buttons into categories.
My question is, can anyone suggest an efficient way to set up these buttons without hard-coding each of them with text, that would allow me to delete or add buttons and not have to realign the buttons over their matching text each time? I'm thinking that setting up hittest clips as buttons is the best solution (allowing each piece of dynamic text therein to have it's own custom text), but for 40 buttons or so? What a pain.
Add all the items into arrays (based on header), then loop through the arrays and set the x and y values of each item based on where your iteration is at. It's possible to do the whole thing through code (MX or later) - no symbols required.
If this is beyond your abilities, I can have a go at it. It'll have to wait until I get home though (about 1 or 2 hours from now). I could probably try it just in Notepad, but the result would have a high probability of having problems. It usually takes a bit of testing.
Okay, I decided to do it in Notepad anyway. I make no claims that this will even compile, let alone work. I'll figure out any inevitable bugs when I get home.
Hey, that is one sweet piece of code and despite your doubts, it seems to be working fine. That you are able to handcode that in Notepad is something that I can only marvel at.
If I may, I have just two or three questions.
1 - Do I have to repeat this section of code (with changed labels, headers, etc) for each button? It looks like I have to, but I just want to check
Okay, I got home and was able to test it... there were some bugs, so I fixed it and updated the code above.
1. I don't really understand your question here. You listed a function... the purpose of a function is so that you only have to code something once. The code I gave is enough to generate ALL buttons. It isn't something that should be inside a button. It should be on the main timeline.
2. Yes, this can be altered to use a pre-existing clip. Set the linkage of the clip to something like "genericClip". Then replace the createEmptyMovieClip with attachMovie.
3. Text color is pretty easy as well. I included it in the updated code above.
If you have any more questions, just let me know.
Marshall
*edit* I found some more bugs when a header is the bottom y value before being wrapped around. Just so you know, the code isn't final yet.
Last edited by marshdabeachy; 10-07-2003 at 04:38 PM.
Originally posted by marshdabeachy Okay, I got home and was able to test it... there were some bugs, so I fixed it and updated the code above.
Cool, thanks.
Originally posted by marshdabeachy 1. I don't really understand your question here. You listed a function... the purpose of a function is so that you only have to code something once. The code I gave is enough to generate ALL buttons. It isn't something that should be inside a button. It should be on the main timeline.
No, I'm not thinking the button action should be inside a button symbol - I'm trying to figure how to add the code in the script you gave to offer different actions for the multiple buttons created by the script. I'm thinking that I need to declare the function a number of times in the same keyframe, each with it's own button name and button-specific action. Does that sound about right?
Thanks for the advice on adding the other clip and also the header colors, though I will keep in mind you're not 100% satisified with the piece (although it loooks pretty darn nice to me).
I've almost got it working... I added vertical lines between sections and have one last bug to fix.
I see what you're saying with the individual buttons. If each button is going to do something COMPLETELY different and run a bevy of ActionScript and other stuff, you'll have to set up individual functions for each button. If they are goign to perform similar actions (for example, if each button were to perform a getURL on a different address), then that can be set up right from the array with no extra functions required. It depends on what you want to do with the buttons.
*edit* Okay, the finished code is up above. All bugs should be gone, and it should handle anything you throw at it.
Last edited by marshdabeachy; 10-07-2003 at 05:05 PM.
I don't really need to declare a new function for each, right? I was wondering if you could show mw how to set up a couple of buttons in your script, so that I could follow the pattern for the remaining 38 or so, to be able to do something like the demonstrated actions above.
Okay, I had to do a minor rewrite to the code to handle the new information. I presumed all three lines within the onRelease function you gave would be different for each button, so I included that in the updated code above. The only thing you need to worry about would be the new format at the top of the code.
As you can tell, each array element now stores an object which contains all the info necessary for each button. That info is assigned into the buttons when they are created, then put to use when the button is clicked.
BTW... The method you wanted to try earlier isn't possible. You can't put actions inside arrays. It will evaluate the term and store the result, which means it won't know what to do when you click the button.