Adding & Removing Items Using ActionScript
Besides adding items through the Component Inspector or XML, items can also be added and removed through ActionScript.
If you have not already done so you should first complete the Getting started section of this userguide and then open the file that you created in Flash. You must ensure that the 3DMenu that's on the stage has an instance name. In these examples, we have given the 3DMenu an instance name of menu. These examples also assume that you have a symbol in the library with linkageId (AS2) or Class (AS3) set to item.
For 3DMenu-AS2:
The following code adds an item with linkageId "item" to position x: -50, y: -50, z: 0 and a link value of "home.html". The id for this item is "item1":
var item1:Object = {linkageId:"item",id:"item1",x:-50,y:-50,z:0,link:"home.html"};
menu.addItem(item1);
The first line defines the item and the second line adds the item to the 3DMenu.
You can also add several items at a time by using an array. In this case, you would use the addItems method. For example
var menuData:Array=[{linkageId:"item",id:"item1",x:-50,y:-50,z:0},{linkageId:"item",id:"item2",x:50,y:-50,z:0}];
menu.addItems(menuData);
For 3DMenu-AS3:
The following code adds two items. The first line adds an item with class "item" to position x: -50, y: -50, z: 0 and a link value of "home.html". The id for this item is "item1". The second line adds an item using the instance name of the movie clip that's on the stage. The id for this item is "item2".
var item1:Object = {className:"item",id:"item1",x:-50,y:-50,z:0,link:"home.html"};
var item2:Object = {sprite:"item",id:"item2",x:50,y:-50,z:0,link:"about.html"};
menu.addItem(item1);
menu.addItem(item2);
You can also add several items at a time by using an array. In this case, you would use the addItems method. For example
var menuData:Array=[{className:"item",id:"item1",x:-50,y:-50,z:0},{className:"Item",id:"item2",x:50,y:-50,z:0}];
menu.addItems(menuData);
Note: Items that already exist will not be removed automatically. In order to remove all items, you should use the removeAll() method as explained in the ActionScript reference.