In this help section you'll learn about adding actions to your menu buttons.

About Button IDs:

Each button has an ID that is unique across the menu. Using this ID you will be able to add actions to each button and check which button is selected whenever you need to.

By default the buttons receive IDs that are related to their order in the menu. For example, if we use the following menu structure:

Home
Products
>Creative Movie FX
>Creative Text FX
>Creative DW Drop Down Menu
Company
>About
>Contact

The buttons will have the following IDs:

Home – button_1
Products – button_2
Creative Movie FX – button_2_1
Creative Text FX – button_2_2
Creative DW Drop Down Menu – button_2_3
Company – button_3
About – button_3_1
Contact – button_3_2

You can also specify custom IDs so you can easily identify each menu button. This can be especially helpful when you have many submenus. To add a custom ID you just have to type the ID preceded by "id=" in the menu structure at the end of each line, separated by a comma. The above example will look like this when using custom IDs:

Home,id=hom
Products,id=prd
>Creative Movie FX,id=cmfx
>Creative Text FX,id=ctfx
>Creative DW Drop Down Menu,id=cddm
Company,id=com
>About,id=abt
>Contact,id=con

The "changed" event:

Whenever the selected button changes the "changed" event is triggered. Also, the "selectedID" property holds the ID of the selected menu button. So, by using this event you can check to see which button was selected and execute the appropriate actions. For example, if the menu instance is called "my_menu" the code would look like this:

In this example we will use the folowing menu structure:

Home,id=hom
Products,id=prd
>Creative Movie FX,id=cmfx
>Creative Text FX,id=ctfx
>Creative DW Drop Down Menu,id=cddm
Company,id=com
>About,id=abt
>Contact,id=con



var menu_listener = new Object();
menu_listener.changed = function() {
switch (my_menu.selectedID) {
case "hom": trace("The Home button was selected"); break;
case "ctfx": trace("The Creative Text FX button was selected"); break;
case "con": trace("The Contact button was selected"); break;
} } my_menu.addListener(menu_listener);


Adding actions to buttons individually

There is also another way of adding actions to buttons, individually. For example, if you want to add an action for the Products button (having "prd" as ID) in the example above, the code would look like this:



my_menu.actions["prd"] = function() {
trace("The Products button was selected"); }


Selecting a menu button from ActionScript

Sometimes, you may want to change the website section from outside the menu (using a link, button, etc.) and the menu will have to select the corresponding button to reflect the change. To do this you have to use the "active" property of the button. For example, if you want to select the Home button (having "hom" as ID) in the example above you will have to use the following line of code:



my_menu.selectButton("hom");

Note that this only selects the button in the menu, but does not trigger the button actions or the "changed" event (in order to give you more flexibility regarding what actions you want to execute).