# XML Menu (giving mc unique instance name)

**URL:** <https://forum.kirupa.com/t/xml-menu-giving-mc-unique-instance-name/262057>\
**Category:** flash\
**Created:** [June 3, 2008, 1:14am UTC](https://forum.kirupa.com/t/xml-menu-giving-mc-unique-instance-name/262057 "2008-06-03T01:14:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craig\_clayton](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@craig\_clayton](https://forum.kirupa.com/u/craig_clayton)\
**Post date:** [June 3, 2008, 1:14am UTC](https://forum.kirupa.com/t/xml-menu-giving-mc-unique-instance-name/262057/1 "2008-06-03T01:14:30Z")

</div>

Ok so I found this [tutorial](http://flashmymind.com/index.php?view=article&catid=15%3Acreating-a-menu-via-xml&id=15%3Acreating-a-menu-via-xml&option=com_content&Itemid=15) for building an XML menu but what it fails to do explain how to give each nav an instance name so I can bring in content or whatever. Can anyone please tell me what I need to do so that I can add an event listener to each movieclip. Thanks in advance if you can help. I am also looking for more in depth xml tutorials or books that will teach how to search nodes (I know how to search with a trace but not how to attach it to a button), or any other advanced techniques using xml.

Thanks in advanced

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [June 3, 2008, 1:39am UTC](https://forum.kirupa.com/t/xml-menu-giving-mc-unique-instance-name/262057/2 "2008-06-03T01:39:25Z")

</div>

in the for each statement, add this below the instantiation:

```auto

menuItem = [COLOR=#000000] **new** [/COLOR] MenuItem[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];

// ADD THIS LINE
menuItem.name = link.@name + "_mc";

menuItem.menuLabel.text = [[COLOR=#000066]link[/COLOR]](http://www.php.net/link).@name;

```

that should work, names wil be  
Home\_mc  
Works\_mc  
About\_mc  
Contact\_mc

---

<div class="post-metadata">

**Author:** ![craig\_clayton](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@craig\_clayton](https://forum.kirupa.com/u/craig_clayton)\
**Post date:** [June 3, 2008, 2:14am UTC](https://forum.kirupa.com/t/xml-menu-giving-mc-unique-instance-name/262057/3 "2008-06-03T02:14:52Z")

</div>

[quote=creatify;2335230]in the for each statement, add this below the instantiation:  
ActionScript Code:  
[LEFT]menuItem = \<font [COLOR=#0000FF]color[/COLOR]=[COLOR=#FF0000]"#000000"[/COLOR]\>\<b\>new\</b\>\</font\> MenuItem\<font [COLOR=#0000FF]color[/COLOR]=[COLOR=#FF0000]"#66CC66"[/COLOR]\>[COLOR=#000000]([/COLOR]\</font\>\<font [COLOR=#0000FF]color[/COLOR]=[COLOR=#FF0000]"#66CC66"[/COLOR]\>[COLOR=#000000])[/COLOR]\</font\>;

[COLOR=#808080]_// ADD THIS LINE_[/COLOR]  
menuItem.[COLOR=#0000FF]name[/COLOR] = link.@[COLOR=#0000FF]name[/COLOR] + [COLOR=#FF0000]"\_mc"[/COLOR];

menuItem.[COLOR=#000080]menuLabel[/COLOR].[COLOR=#0000FF]text[/COLOR] = \<a href=[COLOR=#FF0000]“[http://www.php.net/link](http://www.php.net/link)”[/COLOR] [COLOR=#0000FF]target[/COLOR]=[COLOR=#FF0000]"\_blank"[/COLOR]\>\<font [COLOR=#0000FF]color[/COLOR]=[COLOR=#FF0000]"#000066"[/COLOR]\>link\</font\>\</a\>.@[COLOR=#0000FF]name[/COLOR];  
[/LEFT]

that should work, names wil be  
Home\_mc  
Works\_mc  
About\_mc  
Contact\_mc[/quote]

Thank you very much

---

<div class="post-metadata">

**Author:** ![craig\_clayton](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@craig\_clayton](https://forum.kirupa.com/u/craig_clayton)\
**Post date:** [June 3, 2008, 2:24am UTC](https://forum.kirupa.com/t/xml-menu-giving-mc-unique-instance-name/262057/4 "2008-06-03T02:24:01Z")

</div>

This is what I did with that function since I am not trying to link external pages but I want to link it to other mc’s etc

> 

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 settingsXML.links..link) {
	menuItem = new MenuItem();

	//Insert the menu text (link.@name reads the link's "name" attribute)
	menuItem.menuLabel.text = link;
	menuItem.name = link;
	
	//If the text is longer than the textfield, autosize so that the text is treated as left-justified
	menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;
	
	//Insert the menu button to stage
	menuItem.x = 20;
	menuItem.y = 20 + i * 25;
	
	//Make the button look like a button (hand cursor)
	menuItem.buttonMode = true;
	menuItem.mouseChildren = false;
	
	//Add event handlers
	//menuItem.addEventListener (MouseEvent.CLICK, mouseClickHandler);
	
	
	addChild(menuItem);
	
	//Increment the menu button counter, so we know how many buttons there are
	i++;
}

```

}

So now my instance names are Home, About, etc… but I cant add an event listener because flash says its an undefined property so how do I get around this.

---

<div class="post-metadata">

**Author:** ![craig\_clayton](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@craig\_clayton](https://forum.kirupa.com/u/craig_clayton)\
**Post date:** [June 3, 2008, 1:27pm UTC](https://forum.kirupa.com/t/xml-menu-giving-mc-unique-instance-name/262057/5 "2008-06-03T13:27:07Z")

</div>

Anyone?
