August
15, 2000
updated August 2002. See below.
Hierarchical Menus in FlashI was working on a project that was going to require a hierarchical menu structure, similar to how Windows Explorer or the Macintosh List view worked. You clicked on the arrow or plus sign, and a sublist of items would expand below it pushing everything else down. Well I thought that this would be extremely difficult in Flash, so I made a cry out to the wonderful people in the Flash Newsgroup. A very generous fellow by the name of Mark Rainer came answering and sent me a Flash file that was amazingly close to what I was looking for. Then I went in and did some customizations of my own and below is the results. I've given you three different options to choose from below. You can pick the best one for your needs. Update: All of these menu samples have been updated for Flash 5 and above. I have cleaned up the code significantly (especially for sample 4) and have done more thorough testing to make sure that they work properly. I also removed the 2nd Hierarchical menu sample as it was so close to the 3rd sample that it was too redundant.
Version: 5 and above |
||||||||||||||||||||||||||||||||||||||||||||
|
The ActionScript that runs this beauty is very simple:
What you see above is one part of the script. Basically what is happening here, is that you set the property of one part of the menu (the Y position) based on the Y positions of both the previous menu and the previous submenu. This is added together to give you a result that moves the menus down. Finally, you add that last number (18) to space out the menus more. For every menu instance, you duplicate that script to move all of the menus at once. Download the FLA sample below to see how it all works.
Full Hierarchy (Sample 2 + 3)
Open/Close Hierarchy (Sample 4)
You are free to use this technique in your Flash movies on one condition. Just send me an e-mail letting me know how you used it so I can see what the world is coming up with using this very cool system. If you have any further questions on how it was done, just drop me a note. See my other techniques in Flash:
Ian Kelleigh
Visit my site all about FreeHand and see
other tips with Flash. |
||||||||||||||||||||||||||||||||||||||||||||