PDA

View Full Version : Navigation/Sub Menu help (xml/AS2/Arrays)


farther_north
04-26-2010, 03:09 PM
I am working on a multi-level navigation and have run into some issues. The arrays seem to be working, I am able to see the content and trace the variables.

However, when I am trying to set the functions when the buttons are pressed - the variables become undefined. My code is here:

// Setting arrays

var menuButtons:Array = new Array();
menuButtons = siteConfigArray[0][0];
trace("totalSections : " +menuButtons.length);
var subMenu:Array = new Array();

// loads the data into arrays
for(i=0;i<menuButtons.length;i++){

for(j=0;j<menuButtons[i].length;j++){
subMenu[i] = menuButtons[i]
}
}

var chosenMenu:Array = new Array();
var subMenuOpened:Boolean = false;
var whichSubMenu:Number = new Number();
var currentPosition:Number = new Number();

for (i=0; i<menuButtons.length; i++) {
this.attachMovie("menu button", "menuButton"+i, this.getNextHighestDepth());
this["menuButton"+i]._x = 30+(115*i);
this["menuButton"+i]._y = 6;
this["menuButton"+i].label_txt.text = menuButtons[i].title;
var mainMenuColor:Color = new Color(this["menuButton"+i].bkgColor_mc);
mainMenuColor.setRGB(0x006699);
this["menuButton"+i].onRollOver = function():Void {

loadNewSection(chosenMenu[j].module, chosenMenu[j].title, chosenMenu
[j].module_id);

whichSubMenu = Number(this._name.substr(-1, 1));
currentPosition = this._x;
if (!subMenuOpened) {
subMenuOpened = true;
openSubMenu(whichSubMenu, currentPosition);
} else {
closeSubMenu();
openSubMenu(whichSubMenu, currentPosition);
}
};
}

function openSubMenu(whichSubMenu, currentPosition):Void {
chosenMenu = eval("subMenu"+(whichSubMenu+1));
for (j=0; j<chosenMenu.length; j++) {
this.createEmptyMovieClip("subMenuHolder_mc", this.getNextHighestDepth());
subMenuHolder_mc.attachMovie("menu button", "subMenuButton"+j, this.getNextHighestDepth());
subMenuHolder_mc["subMenuButton"+j]._x = currentPosition;
subMenuHolder_mc["subMenuButton"+j]._y = 29+(j*23);
subMenuHolder_mc["subMenuButton"+j].label_txt.text = chosenMenu[j].title;
var subMenuStartColor:Color = new Color(subMenuHolder_mc["subMenuButton"+j].bkgColor_mc);
subMenuStartColor.setRGB(0x81A3E2);
subMenuHolder_mc["subMenuButton"+j].onRelease = subMenuHolder_mc["subMenuButton"+j].onReleaseOutside=function ():Void {
loadNewSection(chosenMenu[j].module, chosenMenu[j].title, chosenMenu[j].module_id);
closeSubMenu();
};
subMenuHolder_mc["subMenuButton"+j].onRollOver = function():Void {
var subMenuRollOverColor:Color = new Color(this.bkgColor_mc);
subMenuRollOverColor.setRGB(0xFF6600);
};
subMenuHolder_mc["subMenuButton"+j].onRollOut = function():Void {
var subMenuRollOutColor:Color = new Color(this.bkgColor_mc);
subMenuRollOutColor.setRGB(0x81A3E2);
};
}
}

I feel like I am really close.

farther_north
04-26-2010, 07:53 PM
I have further isolated the issue.. this is exactly how my acctionscript appears.

these lines trace to values:
trace("Menu module_id above onrollover : " +menuButtons[i].module_id);
trace("Menu module : " +menuButtons[i].module);
trace("Menu link : " +menuButtons[i].direct_link);
trace("Menu title : " +menuButtons[i].title);

this["menuButton"+i].onRollOver = function():Void {
// these trace to undefined
trace("Menu module_id below onrollover : " +menuButtons[i].module_id);
trace("Menu module : " +menuButtons[i].module);
trace("Menu link : " +menuButtons[i].direct_link);
trace("Menu title : " +menuButtons[i].title);

tacos
04-27-2010, 03:04 AM
What does the value of i alone trace to in the onRollOver?