all groups > flash actionscript > june 2004 >
You're in the

flash actionscript

group:

xml menu with dynamic mc's not working properly


xml menu with dynamic mc's not working properly Valkyrie
6/27/2004 9:42:24 PM
flash actionscript: I hope someone here can help me figure this out, 'cause I've been working on it
for a solid week and can't find the issue. I have a menu that's populated by
XML that will need to go to three levels. When it's populated up to the
secondary level, it's mostly fine, but populating the tertiary level makes the
whole thing blow up in my face. Here's the code (minus the showMenu() &
buildLinks() functions, which aren't relevant to this problem & would only
clutter this up :) ):

stop();

var counter = 0;
var subCounter = 0;
var tertCounter = 0;
setVariable("whichOne", 0);
setVariable("whichOneSub", 0);
setVariable("whichOneTert", 0);
var contentHolder = createEmptyMovieClip("content", 2);



menuXML = new XML();
menuXML.ignoreWhite = true;
menuXML.load('XML/menu.xml');
menuXML.onLoad = loadSuccess;


function loadSuccess(success) {
if (!success) {
trace("xml load failed");
return;
} else {
// trace("xml load successful");
buildNav();
buildLinks()
}
}


function buildNav() {

// prototypes to separate out number of different kinds of nodes

Object.prototype.childrenOfType = function(s,a) {
if (a == undefined) {
a = new Array();
}
var n = this.firstChild;
while (n) {
if (n.nodeName==s) {
a.push(n);
}
n = n.nextSibling;
}
return a;
}

Object.prototype.firstChildOfType = function(s) {
var n = this.firstChild;
while (n) {
if (n.nodeName==s) {
return n;
}
n = n.nextSibling;
}
return null;
}

ASSetPropFlags(Object.prototype,null,7);

// determine how many of the main nav items there will be
numOfModules =
menuXML.firstChildOfType('menu').childrenOfType('module').length;

// loop through each nav item to determine how many pages it has
for (j = 0; j < numOfModules; j++) {

numOfSections =
menuXML.firstChildOfType('menu').childrenOfType('module')[j].childrenOfType('sec
tion').length;
writeMenu();

// build secondary nav based on numOfSections
for (k = 0; k < numOfSections; k++) {

writeSubMenu(j+1,k+1,"null"); // write the secondary nav item
numOfPages =
menuXML.firstChildOfType('menu').childrenOfType('module')[j].childrenOfType('sec
tion')[k].childrenOfType('page').length;

// if there is more than one page under a section, build the tertiary
submenu
if (numOfPages > 1) {

for (m = 0; m < numOfPages; m++) {
writeSubMenu(j+1,k+1,m+1); // write the tertiary nav item
}

} // end if numOfPages

} // end for k

} // end for j

} // end function


var stretch = 155;

function writeMenu() {

counter++;
var tempName =
menuXML.firstChildOfType('menu').childrenOfType('module')[counter -
1].attributes.name;
var nameStr = tempName.toString();
var nameStrLen = nameStr.length;

var secLinkArray = new Array();
var modLinkArray = new Array();

if (counter == 1) {

if (nameStrLen <= 26) {

attachMovie("_root.bnav", "bnav", counter);
setProperty("bnav", _x, 105);
setProperty("bnav", _y, 106.1);
bnav.title = nameStr;
secLinkArray[0] = 0;
modLinkArray[0] = "";
bnav.intro.onRollOver = function() {
showSubMenu(secLinkArray[0], modLinkArray[0], "sec");
}

bnav.intro.onRollOut = function() {
hideSubMenu();
}

bnav.intro.onPress = function() {
showSubMenu(secLinkArray[0], modLinkArray[0], "sec");
}
_global.whichOne = 1;
stretch = stretch + bnav._height;

} else if (nameStrLen > 26 && nameStrLen <= 52) {

attachMovie("_root.bnav2lines", "bnav2lines", counter);
setProperty("bnav2lines", _x, 105);
setProperty("bnav2lines", _y, 106.1);
bnav2lines.title = nameStr;
secLinkArray[0] = 0;
modLinkArray[0] = "";
bnav2lines.intro.onRollOver = function() {
showSubMenu(secLinkArray[0], modLinkArray[0], "sec");
}

bnav2lines.intro.onRollOut = function() {
hideSubMenu();
}

bnav2lines.intro.onPress = function() {
showSubMenu(secLinkArray[0], modLinkArray[0], "sec");
}
_global.whichOne = 2;
stretch = stretch + bnav._height;

} else {
trace("Title is larger than 52 characters.");
}

} else {

var less = counter - 1;
trace("less is " + less);

if (_global.whichOne == 1) {
if (counter == 2) {
var prevBtn = eval("bnav");
} else {
prevBtn = eval("bnav" + less);
}
var lastX = 105;
var lastY = prevBtn._y;
var lastHeight = prevBtn._height;
var drop = lastY + lastHeight;
stretch = stretch + lastHeight;

} else if (_global.whichOne == 2) {
if (counter == 2) {
prevBtn = "bnav2lines";
} else {
prevBtn = eval("bnav2lines" + less);
}
lastX = 105;
lastY = prevBtn._y;
lastHeight = prevBtn._height;
drop = lastY + lastHeight;
stretch = stretch + lastHeight;
}

var currHeight = navshadow._height;
var percent = Math.round((stretch / currHeight) * 100);

if (stretch > currHeight) {
setProperty("navshadow", _yscale, percent);
setProperty("bottom", _y, stretch+19.5);
}

if (nameStrLen <= 26) {

tempID = "bnav" + counter;
attachMovie("bnav", tempID, counter);
setProperty(tempID, _x, lastX);
setProperty(tempID, _y, drop);
tempVal = eval("bnav" + counter);
trace("tempVal is " + tempVal + " and prevBtn is " + prevBtn + " and lastX
is " + lastX + " and drop is " + drop + "\n");

tempVal.title = nameStr;

var tempCountVar = counter - 1;
secLinkArray[tempCountVar] = tempCountVar;
modLinkArray[tempCountVar] = "";

tempVal.intro.onRollOver = function () {
showSubMenu(secLinkArray[tempCountVar], modLinkArray[tempCountVar], "sec");
}
tempVal.intro.onRollOut = function () {
hideSubMenu();
}
tempVal.intro.onPress = function() {
showSubMenu(secLinkArray[tempCountVar], modLinkArray[tempCountVar], "sec");
}

_global.whichOne = 1;

} else if (nameStrLen > 26 && nameStrLen <= 52) {

tempID = "bnav2lines" + counter;
attachMovie("bnav2lines", tempID, counter);
setProperty(tempID, _x, lastX);
setProperty(tempID, _y, drop+5);
tempVal = eval("bnav2lines" + counter);
trace("tempVal is " + tempVal + " and prevBtn is " + prevBtn + " and lastX
is " + lastX + " and drop is " + drop + "\n");

tempVal.title = nameStr;

tempCountVar = counter - 1;
secLinkArray[tempCountVar] = tempCountVar;
modLinkArray[tempCountVar] = "";

tempVal.intro.onRollOver = function () {
showSubMenu(secLinkArray[tempCountVar], modLinkArray[tempCountVar], "sec");
}
tempVal.intro.onRollOut = function () {
Re: xml menu with dynamic mc's not working properly Valkyrie
6/28/2004 10:15:24 AM
AddThis Social Bookmark Button