Hi!
I have some trouble with multilevel menu trace. Can you help me:
function part(id:Number, parent:Number, visible:Boolean, title:String):Object{
this.id = id;
this.parent = parent;
this.visible = visible;
this.title = title;
return this;
}
var parts:Array = new Array();
parts[0] = new part(1, 0, true, "Part 1");
parts[1] = new part(2, 1, true, "Part 2");
parts[2] = new part(3, 1, true, "Part 3");
parts[3] = new part(4, 2, true, "Part 4");
parts[4] = new part(5, 2, true, "Part 5");
parts[5] = new part(6, 0, true, "Part 6");
parts[6] = new part(7, 0, true, "Part 7");
var partsLength:Number = parts.length;
function traceMenu(parent:Number):Void{
for(i=0; i<partsLength; i++){
if(parts[i].parent == parent && parts[i].visible){
trace(parts[i].title);
traceMenu(parts[i].id);
}
}
}
traceMenu(0);
kglad - 31 Aug 2005 15:11 GMT
your for-loop will never complete unless the conditions are met by none of your objects.
Notacia - 31 Aug 2005 20:44 GMT
NSurveyor - 31 Aug 2005 21:00 GMT
I don't know what you are trying to do... can you explain what you are trying to accomplish?
BTW shouldn't you be using for(var i=0;.... not for(i=0
Notacia - 31 Aug 2005 21:15 GMT
I need to trace the multilevel menu by recursive function
for example:
Part 1
Part 2
Part 4
Part 5
Part 3
Part 6
Part 7
NSurveyor - 31 Aug 2005 21:41 GMT
You're welcome. In case you don't know why that one word: var caused your
problems...
Throughout your original code, you used the same variable i. So if i was say
3, and it called traceMenu, it would make that same i 0 again...