XML Menu loading new SWF w/ Transition! Yaa!

I’ve got a dynamic menu using XML. Works great.
I’ve got a movieclip called “content” into which you’d load SWF’s and a movieclip called “transition” which fade in and out when you load the new SWF’s.

How do I combine the two, because the menu is dynamic from XML I don’t know how do address the buttons. Please help me!!

See attached ZIP File.

Thanks.

Ads.

I’ve changed the “action” to ready “loadSWF” and the variable as the target SWF I want to load in the XML file…


<?xml version="1.0"?>
<menu name="example">
	<item name="Introduction" action="loadSWF" variables="home.swf"/>
</menu>

Now in the flash actionscript I’ve put the following


// generates a list of menu items (effectively one menu)
// given the inputted parameters.  This makes the main menu
// as well as any of the submenus
GenerateMenu = function(container, name, x, y, depth, node_xml) {
	// variable declarations
	var curr_node;
	var curr_item;
	var curr_menu = container.createEmptyMovieClip(name, depth);
	
	// for all items or XML nodes (items and menus)
	// within this node_xml passed for this menu
	for (var i=0; i<node_xml.childNodes.length; i++) {
		// movieclip for each menu item
		curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
		curr_item._x = x;
		curr_item._y = y + i*curr_item._height;
		curr_item.trackAsMenu = true;
		
		// item properties assigned from XML
		curr_node = node_xml.childNodes*;
		curr_item.action = curr_node.attributes.action;
		curr_item.variables = curr_node.attributes.variables;
		curr_item.name.text = curr_node.attributes.name;
		
		// item submenu behavior for rollover event
		if (node_xml.childNodes*.nodeName == "menu"){
			// open a submenu
			curr_item.node_xml = curr_node;
			curr_item.onRollOver = curr_item.onDragOver = function(){
				var x = this._x + this._width - 5;
				var y = this._y + 5;
				GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml);
				// show a hover color
				this.name.textColor = (0xFFFFFF);
				var col = new Color(this.background);
				col.setRGB(0x008185);
			};
		}else{ // nodeName == "item"
			curr_item.arrow._visible = false;
			// close existing submenu
			curr_item.onRollOver = curr_item.onDragOver = function(){
				curr_menu.submenu_mc.removeMovieClip();
				// show a hover color
				this.name.textColor = (0xFFFFFF);
				var col = new Color(this.background);
				col.setRGB(0x008185);
			};
		}
		
		curr_item.onRollOut = curr_item.onDragOut = function(){
			// restore color
			this.name.textColor = (0x004445);
			var col = new Color(this.background);
			col.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
		};
		
		// any item, menu opening or not can have actions
		curr_item.onRelease = function(){
			Actions[this.action](this.variables);
			CloseSubmenus();
		};
	} // end for loop
};

// create the main menu, this will be constantly visible
CreateMainMenu = function(x, y, depth, menu_xml){
	// generate a menu list
	GenerateMenu(this, "mainmenu_mc", x, y, depth, menu_xml.firstChild);
	// close only submenus if visible durring a mouseup
	// this main menu (mainmenu_mc) will remain
	mainMenu_mc.onMouseUp = function(){
		if (mainmenu_mc.submenu_mc && !mainmenu_mc.hitTest(_root._xmouse, _root._ymouse, true)){
			CloseSubmenus();
		}
	};
};

// closes all submenus by removing the submenu_mc
// in the main menu (if it exists)
CloseSubmenus = function(){
	mainmenu_mc.submenu_mc.removeMovieClip();
};

// This actions object handles methods for actions
// defined by the XML called when a menu item is pressed

Actions = Object();
Actions.loadSWF = function(SWFVar) {
	if (section != SWFVar+".swf") {
		section = SWFVar+".swf";
		_root.transition.gotoAndPlay("closing");
	}
}
	
Actions.newMenu = function(menuxml){
	menu_xml.load(menuxml);
};

// load XML, when done, run CreateMainMenu to interpret it
menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function(ok){
	// create main menu after successful loading of XML
	if (ok){
		CreateMainMenu(1, 115, 0, this);
	}else{
		message_txt.text = "Error Loading XML";
	}
};
// load first XML menu
menu_xml.load("menu.xml");



// preload function and transition
this.createEmptyMovieClip("temp", 1000);
function preload() {
	this.transition.txtPercentage = "";
	temp.onEnterFrame = function() {
		var t = this._parent.content.getBytesTotal(), l = this._parent.content.getBytesLoaded();
		if (t) {
			var percent = Math.round(l*100/t);
			if (l == t) {
				this._parent.transition.gotoAndPlay("opening");
				this._parent.transition.txtPercentage = "Done Loading";
				delete this.onEnterFrame;
			} else {
				this._parent.transition.txtPercentage = percent+" %";
			}
		} else {
			this._parent.transition.txtPercentage = "";
		}
	};
}

Its begining to make sence bit by bit to my mangled head but it still isn’t working. Can anyone help!?!

Ads.

I’ve cracked it!


// generates a list of menu items (effectively one menu)
// given the inputted parameters.  This makes the main menu
// as well as any of the submenus
GenerateMenu = function(container, name, x, y, depth, node_xml) {
	// variable declarations
	var curr_node;
	var curr_item;
	var curr_menu = container.createEmptyMovieClip(name, depth);
	
	// for all items or XML nodes (items and menus)
	// within this node_xml passed for this menu
	for (var i=0; i<node_xml.childNodes.length; i++) {
		// movieclip for each menu item
		curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
		curr_item._x = x;
		curr_item._y = y + i*curr_item._height;
		curr_item.trackAsMenu = true;
		
		// item properties assigned from XML
		curr_node = node_xml.childNodes*;
		curr_item.action = curr_node.attributes.action;
		curr_item.variables = curr_node.attributes.variables;
		curr_item.name.text = curr_node.attributes.name;
		
		// item submenu behavior for rollover event
		if (node_xml.childNodes*.nodeName == "menu"){
			// open a submenu
			curr_item.node_xml = curr_node;
			curr_item.onRollOver = curr_item.onDragOver = function(){
				var x = this._x + this._width - 5;
				var y = this._y + 5;
				GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml);
				// show a hover color
				this.name.textColor = (0xFFFFFF);
				var col = new Color(this.background);
				col.setRGB(0x008185);
			};
		}else{ // nodeName == "item"
			curr_item.arrow._visible = false;
			// close existing submenu
			curr_item.onRollOver = curr_item.onDragOver = function(){
				curr_menu.submenu_mc.removeMovieClip();
				// show a hover color
				this.name.textColor = (0xFFFFFF);
				var col = new Color(this.background);
				col.setRGB(0x008185);
			};
		}
		
		curr_item.onRollOut = curr_item.onDragOut = function(){
			// restore color
			this.name.textColor = (0x004445);
			var col = new Color(this.background);
			col.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
		};
		
		// any item, menu opening or not can have actions
		curr_item.onRelease = function(){
			Actions[this.action](this.variables);
			CloseSubmenus();
		};
	} // end for loop
};

// create the main menu, this will be constantly visible
CreateMainMenu = function(x, y, depth, menu_xml){
	// generate a menu list
	GenerateMenu(this, "mainmenu_mc", x, y, depth, menu_xml.firstChild);
	// close only submenus if visible durring a mouseup
	// this main menu (mainmenu_mc) will remain
	mainMenu_mc.onMouseUp = function(){
		if (mainmenu_mc.submenu_mc && !mainmenu_mc.hitTest(_root._xmouse, _root._ymouse, true)){
			CloseSubmenus();
		}
	};
};

// closes all submenus by removing the submenu_mc
// in the main menu (if it exists)
CloseSubmenus = function(){
	mainmenu_mc.submenu_mc.removeMovieClip();
};

**
// This is where you define the variable that will load the SWF. The targetis
//defined under each buttons entry in the menu.xml file

// This actions object handles methods for actions
// defined by the XML called when a menu item is pressed

Actions = Object();
	Actions.loadSWF = function(targetSWF) {
		if (section != targetSWF) {
		section = targetSWF;
		_root.transition.gotoAndPlay("closing");
	};
}**

Actions.newMenu = function(menuxml){
	menu_xml.load(menuxml);
};

// load XML, when done, run CreateMainMenu to interpret it
menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function(ok){
	// create main menu after successful loading of XML
	if (ok){
		CreateMainMenu(1, 110, 0, this);
	}else{
		message_txt.text = "Error Loading XML";
	}
};
// load first XML menu
menu_xml.load("menu.xml");



// preload function and transition
this.createEmptyMovieClip("temp", 1000);
function preload() {
	this.transition.txtPercentage = "";
	temp.onEnterFrame = function() {
		var t = this._parent.content.getBytesTotal(), l = this._parent.content.getBytesLoaded();
		if (t) {
			var percent = Math.round(l*100/t);
			if (l == t) {
				this._parent.transition.gotoAndPlay("opening");
				this._parent.transition.txtPercentage = "Done Loading";
				delete this.onEnterFrame;
			} else {
				this._parent.transition.txtPercentage = percent+" %";
			}
		} else {
			this._parent.transition.txtPercentage = "";
		}
	};
}

Also don’t forget to create the movieclip “content” into which all the target SWF’s load!! I made that mistake. If anyone needs any help on this please let me know.