// set template not visible
_root.MenuTemplate._visible = 0;
// set initial Name and Depth Index
MenuNameIndex = 0;
_root.greatestDepth = 0
// define MenuItem count and clickedNamefor clickUp and clickDown actions
_root.menuCount = 0
_root.clicked = ""
_root.numItems = 0
// define MenuDef class
function MenuDef (MenuDefString) {
this.index = 1;
this.MenuString = MenuDefString;
this.token = "";
}
// define MenuDef methods: getNextToken and peekNextToken
MenuDef.prototype.getNextToken = function () {
if ( this.index < length ( this.MenuString ) ) {
nextChar = substring(this.MenuString, this.index, 1);
if (nextChar == "(") {
this.index += 1;
this.token = nextchar;
return this.token;
}
else if (nextChar == ")") {
this.index += 1;
this.token = nextchar;
return this.token;
}
else if (nextChar == ",") {
this.index += 1;
this.token = nextchar;
return this.token;
}
else {
this.token = "";
while (nextChar != "(" and nextChar != ")" and nextChar!= ",") {
this.token = this.token + nextChar;
this.index += 1;
nextChar = substring(this.MenuString, this.index, 1);
}
return this.token;
}
}
else {
return "";
}
};
MenuDef.prototype.peekNextToken = function () {
if ( this.index < length ( this.MenuString ) ) {
nextChar = substring(this.MenuString, this.index, 1);
if (nextChar == "(") {
this.oldindex = this.index;
this.index += 1;
this.token = nextchar;
this.index = this.oldindex;
return this.token;
}
else if (nextChar == ")") {
this.oldindex = this.index;
this.index += 1;
this.token = nextchar;
this.index = this.oldindex;
return this.token;
}
else if (nextChar == ",") {
this.oldindex = this.index;
this.index += 1;
this.token = nextchar;
this.index = this.oldindex;
return this.token;
}
else if (nextChar != "(" and nextChar != ")" and nextChar != ",") {
this.oldindex = this.index;
this.token = "";
while (nextChar != "(" and nextChar != ")" and nextChar != ",") {
this.token = this.token + nextChar;
this.index += 1;
nextChar = substring(this.MenuString, this.index, 1);
}
this.index = this.oldindex;
return this.token;
}
}
else {
return "";
}
}
// create MenuStructure object with definition
_root.MenuStructure = new MenuDef("This(Menu(is,the(most,complex,menu)),that,has(yet,been,put(in)))");
// define Menu function for creating logical Menu
function Menu (parent, prevBro, MenuDepthIndex) {
// Get the new menu item number
MenuNameIndex += 1;
// get next token value
var token = _root.MenuStructure.getNextToken();
// creates MenuItem movieclip
duplicateMovieClip (_root.MenuTemplate, "MenuItem"+MenuNameIndex, MenuNameIndex);
// setup MenuItem initial values
var ThisMenu = _root["MenuItem" + MenuNameIndex];
ThisMenu.parent = parent;
ThisMenu.followBro = null;
ThisMenu.prevBro = prevBro;
ThisMenu.child = null;
ThisMenu._visible = false ;
ThisMenu.menuNumber = MenuNameIndex;
ThisMenu.LevelText.Leveltext = token;
ThisMenu.dirLine._visible = false
ThisMenu.depth = MenuDepthIndex
// peeks following token
var peektoken = _root.MenuStructure.peekNextToken();
// creates next child
if (peektoken == "(") {
token = _root.MenuStructure.getNextToken(); // Sink "("
ThisMenu.child = Menu(ThisMenu, null,MenuDepthIndex+1);
token = _root.MenuStructure.getNextToken(); // Sink ")"
}
// peeks following token
peektoken = _root.MenuStructure.peekNextToken();
// creates following brother
if (peektoken == ",") {
token = _root.MenuStructure.getNextToken(); // Sink ","
ThisMenu.followBro = Menu (parent, ThisMenu,MenuDepthIndex);
}
// sets button text
if (ThisMenu.child == null) {
ThisMenu.LevelButton.Buttontext = "-"
} else {
ThisMenu.LevelButton.Buttontext = "+"
}
//set number of Items
_root.numItems = MenuNameIndex
//returns MenuNumber
return ThisMenu;
}
function setCoords (node) {
if (node != null) {
node._x = 600;
node._y = 450;
setCoords (node.child);
setCoords (node.followBro);
}
}
// create Menu Object and first MenuItem visible
Menu (null,null,0);
setCoords (_root.MenuItem1)
_root.MenuItem1._x = 330
_root.MenuItem1._y = 355
_root.MenuItem1._visible = 1
_root.MenuItem1.openBrothers (1)
_root.MenuItem1.visibleBrothers ()
stop();