views:

21

answers:

1

I'm having issues with the following menu. I've been adapting a script from kirupa into actionscript 3. When I get to the last level of the menu it won't link properly. It always takes the last url of the bunch as the url for all links in that branch of the tree.

Can anyone help me get it to link properly? A zip with the fla and the xml can be found at the following link.

http://www.jdviz.com/projects/xmlmenu.zip

Thanks,

A: 

There's a problem with the closures at the end of the code. The current button is not identified properly.

if (node_xml.childNodes[i].nodeName != "resource") {
//cleared the code for clarity...
        } else {
            curr_item.arrow.visible = false;
            curr_item.addEventListener(MouseEvent.MOUSE_DOWN,  function(e:MouseEvent):void {
            trace(curr_item.urlLink);
            });

        }

change the above to:

var currentButton:MenuItem_mc = new MenuItem_mc();

function mouseOverHandler(e:MouseEvent ):void
{
   currentButton = e.currentTarget as MenuItem_mc;
   currentButton.addEventListener( MouseEvent.CLICK , clickHandler );
}

function clickHandler(e:MouseEvent):void
{
   var btn:MenuItem_mc = event.currentTarget as MenuItem_mc;
   trace( btn.urlLink );
}

if (node_xml.childNodes[i].nodeName != "resource") {
//cleared the code for clarity...
} else {
    curr_item.arrow.visible = false;
    curr_item.addEventListener(MouseEvent.MOUSE_DOWN, mouseOverHandler ); 

        }
PatrickS
That worked great! Thank you so much. Would you mind explaining it a bit? or point me in the right direction as to what topics I need to focus on learning.
JD-
trying to understand someone else's code is a great way to learn, you could try to do it with this example. try to break it down , do a simpler version , with no submenu for instance, then slowly add the complexity until you're capable of redoing it on your own.
PatrickS
Thanks, that's what I'll do.
JD-