# XML Menu has no functionality

**URL:** <https://forum.kirupa.com/t/xml-menu-has-no-functionality/267980>\
**Category:** flash\
**Created:** [August 7, 2008, 8:07pm UTC](https://forum.kirupa.com/t/xml-menu-has-no-functionality/267980 "2008-08-07T20:07:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlyle](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@carlyle](https://forum.kirupa.com/u/carlyle)\
**Post date:** [August 7, 2008, 8:07pm UTC](https://forum.kirupa.com/t/xml-menu-has-no-functionality/267980/1 "2008-08-07T20:07:48Z")

</div>

Hi fellas

Im a novice in the realms of AS3 an have been trying to get some functionality out of an xml menu I produced from a tutorial. the menu looks fine and the rollovers work perfectly but I cant getthe correct script to enable the buttons to navigate to another swf or even just to gotoAndStop at a certain frame. The code im about to post has some go to frame functionality at the end simply because I was running out of ideas.

If you coud show me the loop i need to use in order to identify which menu button shoud direct where id be very grateful.

XML

\<?xml version=“1.0” encoding=“iso-8859-1”?\>  
\<site\>  
\<links\>  
\<link name=“Home” frame=“1” href=“menu.swf”/\>  
\<link name=“Graphics” frame=“2” href=“Portfolio.swf”/\>  
\<link name=“Flash” frame=“3” href=“menu.swf”/\>  
\<link name=“Contact” frame=“4” href=“Portfolio.swf”/\>  
\</links\>  
\</site\>

I previesly had id where frame is now.

Actionscript

//Imports needed for animation  
import fl.transitions.Tween;  
import fl.transitions.easing.\*;

var me = this;  
//XML file path  
//You can use the following path as well if you want…  
var xmlPath:String = “site.xml”;

//The XML data will be inserted into this variable  
var xmlData:XML = new XML();

//Array used for the tween so they won’t get garbage collected  
var tweensArray:Array = new Array();  
//Used later when we animate the buttons  
var buttonTween:Tween;

//load  
var xmlLoader = new URLLoader();  
xmlLoader.load (new URLRequest(xmlPath));  
xmlLoader.addEventListener (Event.COMPLETE, LoadXML);

//This function is called when the XML file is loaded  
function LoadXML (e:Event):void {

```
//Make sure we're not working with a null loader
if ((e.target as URLLoader) != null ) {
    //Insert the loaded data to our XML variable
    xmlData = new XML(xmlLoader.data);
    xmlData.ignoreWhitespace = true;
    //Call the function that creates the whole menu
    createMenu ();
}

```

}  
//-------------------------------------------------  
function createMenu ():void {  
//This will be used to represent a menu item  
var menuItem:MenuItem;  
//Counter  
var i:uint = 0;

```
//Loop through the links found in the XML file
for each (var link:XML in xmlData.links.link) {

    menuItem = new MenuItem();

    //Insert the menu text (link.@name reads the link's "name" attribute)
    menuItem.menuLabel.text = link.@name;

    //If the text is longer than the textfield, autosize so that the text 
    //is treated as left-justified text
    menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;

    //Insert the menu button to stage
    menuItem.x = 20;
    menuItem.y = 30 + i*40;
    menuItem.alpha=.5

    //Make the button look like a button (hand cursor)
    menuItem.buttonMode = true;
    menuItem.mouseChildren = false;

    //Add event handlers (used for animating the buttons)
    menuItem.addEventListener (MouseEvent.MOUSE_OVER, mouseOverHandler);
    menuItem.addEventListener (MouseEvent.MOUSE_OUT, mouseOutHandler);
    menuItem.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);
    // Here is where we listen for the 'onPress' event
    //var listener = new Object();

    addChild (menuItem);

    //Increment the menu button counter, so we know how many buttons there are
    i++;
}

```

}  
//Function is called when the mouse is over a menu button  
function mouseOverHandler (e:Event):void {

```
//Double the width
buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, 1, 1.5, 1, true);    

```

}

//Function is called when the mouse moves out from the menu button  
function mouseOutHandler (e:Event):void {

```
//Tween back original scale
 buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, e.target.scaleX, 1, 1, true);

```

}  
//Function is called when the button is clicked  
function mouseUpHandler (e:Event):void {  
var frame = xmlData.links.frame;  
me.useFrame(frame);  
};  
//trace(xmlData.links.link.@href);

function useFrame(frame) {  
me.frameNumber.text = "frame "+frame;  
me.gotoAndStop(fr
