Creating Menu at runtime using Flash 8/ActionScript 2.0


You can create menu in your flash application using the following code, however, you need to note one thing that you need to import

mx.controls.*;

mx.data.binding.*; (if you need to create Menu using databinding)

here is the code

var mm:Menu = Menu.createMenu(Me);
mm.addMenuItem({label:”All”});
if (aIndustry.length > 0 ) {
aIndustry.sort();
for (var i=0;i
if (aIndustry[i] != “”) {
mm.addMenuItem({label:aIndustry[i]});
}
}
}
mm.swapDepths(mergerbg_sp);
if (_global.styles.Menu == undefined) {
_global.styles.Menu = new CSSStyleDeclaration();
}
_global.styles.Menu.setStyle(“backgroundColor”, 0xFFFFFF);
_global.styles.Menu.setStyle(“borderStyle”, “menuBorder”);
_global.styles.Menu.setStyle(“selectionColor”, 0x6E8ABA);

mm.show(100,200);

var menuListener:Object = new Object();
menuListener.change = function(evt_obj:Object) {
IndustryShown = evt_obj.menuItem.attributes.label;
redisplay();
};
mm.addEventListener(“change”, menuListener);

Important note: You must have the Menu Component in your Library of first flash. i.e. swf file that is called using Object or embed tag library need to have Menu Component.

Hope that helps

,