# Dynamic Context Menu from XML

**URL:** <https://forum.kirupa.com/t/dynamic-context-menu-from-xml/247515>\
**Category:** flash\
**Created:** [December 25, 2007, 3:02am UTC](https://forum.kirupa.com/t/dynamic-context-menu-from-xml/247515 "2007-12-25T03:02:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pips](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/pips/32/941_2.png) [@pips](https://forum.kirupa.com/u/pips)\
**Post date:** [December 25, 2007, 3:02am UTC](https://forum.kirupa.com/t/dynamic-context-menu-from-xml/247515/1 "2007-12-25T03:02:58Z")

</div>

Hi!

I’m trying to make a Context menu with content (labels/links/separators) loaded from an XML file… Here’s what I have:

```auto
import flash.events.Event;
import flash.net.URLRequest;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.ui.ContextMenuBuiltInItems;
import flash.events.ContextMenuEvent;

function onContextXMLLoad(event:Event):void {
	var contextXML:XML = new XML(event.target.data);
	contextXML.ignoreWhitespace = true;

	var contMenu:ContextMenu = new ContextMenu();
	contMenu.hideBuiltInItems();
	this.contextMenu = contMenu;

	for (var i:int = 0; i<contextXML.item.length(); i++) {
		var lab:String = contextXML.item*.label.text();
		var url:String = contextXML.item*.url.text();
		var contMenuItem:ContextMenuItem = new ContextMenuItem(lab);
		contMenu.customItems.push(contMenuItem);
		contMenuItem.separatorBefore = true;
		if (url != "nolink") {
			contMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onContClick, false, 0, true);
		}
	}
}

var contextXMLLoader:URLLoader = new URLLoader();
contextXMLLoader.addEventListener(Event.COMPLETE, onContextXMLLoad, false, 0, true);
contextXMLLoader.load(new URLRequest("context.xml"));

function onContClick(event:ContextMenuEvent) {
	//trace(url)
	//navigateToURL(new URLRequest(event.target.link));
}

```

Everything works fine except one problem - How can I pass the url variable to the “onContClick” function? I tried many different methods but with no result ☹

thnx for any help,  
Philip Seyfi, divita.eu
