Problem with recursive menu and variable scope with mouseovers

Long time listener, first time poster… I solved a similar problem before in AS2, but can’t figure out the solution to this issue.

In the code below, I’m looping through nested xml structure of an unknown number of levels. GenMenu is (or will be) a recursive function that will build each level of the menu. My problem is that I can’t figure out how to reference the variables from an eventlistener function. I need to pass the children node_xml* to the next recursion, as well as set hover styles on the menu links, etc…

I’ve tried several hours of google searches and forum crawling, but can’t find a solution that makes sense. It’s probably something simple, but I’m just not finding it. Any ideas? Thanks.


function GenMenu(container, name, x, y, depth, node_xml) {
    // variable declarations
    var curr_node = new Array();
    var curr_menu:MovieClip = new MovieClip();
    addChild(curr_menu);

    // for all items and submenus within this node_xml passed for this menu
    for (var i=0; i<node_xml.length(); i++) {
        curr_menu["item_" + i] = new MovieClip();
        curr_menu["item_" + i].x = x;
        curr_menu["item_" + i].y = y - i*20;
        curr_menu["item_" + i].trackAsMenu = true;
        curr_menu.addChild(curr_menu["item_" + i]);
        
        var myText:TextField = new TextField();
        myText.text = node_xml*[email protected];
        myText.name = "myText" + i;
        myText.autoSize = TextFieldAutoSize.LEFT;
        curr_menu["item_" + i].addChild(myText);

        curr_menu = node_xml*;
        trace(curr_menu + "this traces correctly...");
    
        curr_menu["item_" + i].addEventListener(MouseEvent.CLICK, myButtonClick);
        function myButtonClick(ev:MouseEvent):void {
            trace("doesn't trace correctly - how do you access node_xml* here? (or any variable for that matter)")
        }
    }
}