# Help needed adding xml sub menu to actionscript

**URL:** <https://forum.kirupa.com/t/help-needed-adding-xml-sub-menu-to-actionscript/313825>\
**Category:** Uncategorized\
**Created:** [September 10, 2010, 5:50pm UTC](https://forum.kirupa.com/t/help-needed-adding-xml-sub-menu-to-actionscript/313825 "2010-09-10T17:50:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daymes](https://avatars.discourse-cdn.com/v4/letter/d/8baadc/32.png) [@daymes](https://forum.kirupa.com/u/daymes)\
**Post date:** [September 10, 2010, 5:50pm UTC](https://forum.kirupa.com/t/help-needed-adding-xml-sub-menu-to-actionscript/313825/1 "2010-09-10T17:50:54Z")

</div>

Hi there, I’m pretty new to coding, I’ve been following (and adapting) a computer arts tutorial to set up an xml driven site, and am having trouble adding sub menus to the actionscript (basically dont know where to start with it - have tried adding script from other tutorials but it all gets too confusing).

I was wondering if anyone out there can help, the main menus are generated from a movie clip (BTN\_PROJECTS\_MAIN) and contain a button (button) and a text box (txt) plus are made of 3 frames to simulate the different button states. The code I’ve been using is as follows :

// Setup some initial variables

// Hide the button that will display a web link  
\_root.theUrl.\_visible = 0;

// Hide the image icons in the project loader  
// The image icons are simply there to make it easier for you to  
// select the movieClip from the main timeline.  
\_root.img\_project.photo\_icon.\_visible = 0;  
\_root.img\_project.img\_holder.photo\_icon2.\_visible = 0;

// name of the folder for all thumbs and swf files  
\_root.imageFolder = “project\_files/”;

// Create arrays ready for the xml data  
namesArray = new Array();  
linksArray = new Array();  
descriptionsArray = new Array();  
filesArray = new Array();

// Load XML doc  
objXML = new XML();  
objXML.onLoad = loadXML;  
objXML.ignoreWhite = true;  
// The name of your XML file  
objXML.load(“ss\_flash\_testing.xml”);

////////////////////////////////////////////////////////////////////// ///////////////////

// onLoad XML function  
function loadXML(success) {  
if (success) {  
// If the XML loads successfully, count how many projects there are in the file.  
\_root.projectCount = this.firstChild.childNodes.length; // PROJECT node in XML file  
// Then run a function that builds arrays out of the XML data.  
SS\_Arrays();  
} else {  
// If the xml data did not load, show message on stage by populating the description field.  
\_root.description = “Error: Could not load XML”;  
}  
}

////////////////////////////////////////////////////////////////////// ///////////////////

function SS\_Arrays() {  
for (var count = 0; count \< \_root.projectCount; count++) {  
var nodeObj = objXML.firstChild.childNodes[count];  
namesArray[count] = nodeObj.attributes.name;  
descriptionsArray[count] = nodeObj.attributes.description;  
linksArray[count] = nodeObj.attributes.link;  
filesArray[count] = nodeObj.attributes.file;  
}  
// run the function to create the thumbnail and list view buttons  
SS\_createButtons();  
}

////////////////////////////////////////////////////////////////////// ///////////////////

var spaceBetween = 60; // space between buttons

function SS\_createButtons() {  
btn\_projects\_main.\_visible = 0;  
btn\_xPos = \_root.btn\_projects\_main.\_x;  
btn\_yPos = \_root.btn\_projects\_main.\_y;

for (count = 0; count \< namesArray.length; count++) {  
duplicateMovieClip(btn\_projects\_main, “btn\_projects” + count, count);

this[“btn\_projects” + count].\_x = btn\_xPos;  
this[“btn\_projects” + count].\_y = btn\_yPos;

this[“btn\_projects” + count].txt.autoSize = “left”;  
this[“btn\_projects” + count].txt.text = namesArray[count];

//set the button width  
this[“btn\_projects” + count].btn.\_width = this[“btn\_projects” + count].txt.\_width;

// determine the new x placement value based on the current button’s width  
btn\_xPos = btn\_xPos + this[“btn\_projects” + count].\_width + spaceBetween;  
}

// anything from here down I have no idea if it’s needed, so I left it

SS\_load\_project(0);

tellTarget(\_root.btn\_projects0){  
gotoAndPlay(3);  
}

\_root.curButton = “0”;  
}

SS\_createButtons(); // to kick off the function

////////////////////////////////////////////////////////////////////// ///////////////////

function SS\_load\_project(arrayNumber){

////////////////////////////////////////////////////////////////////// ///////////////////

// Progress bar stuff: This creates a new movie clip on the stage  
// and shows the progress of the image or file being loaded

\_root.createEmptyMovieClip(“progressBar\_mc”, 1000);  
progressBar\_mc.createEmptyMovieClip(“bar\_mc”, 1001);  
// Using the flash drawing method, draw a box 550px wide by 2px deep  
// with a fill of red (FF0000)  
with (progressBar\_mc.bar\_mc) {  
beginFill(0xFF0000, 100);  
moveTo(0, 0);  
lineTo(660, 0);  
lineTo(660, 2);  
lineTo(0, 2);  
lineTo(0, 0);  
endFill();  
\_xscale = 0;  
}

// set the X & Y positions of the progress bar manually  
//progressBar\_mc.\_x = 160;  
//progressBar\_mc.\_y = 218;

// Or set them to be the same X & Y as the project file/image.  
progressBar\_mc.\_x = img\_project.\_x;  
progressBar\_mc.\_y = img\_project.\_y;

// set the initial width of the bar to zero  
var mclListener:Object = new Object();  
mclListener.onLoadStart = function(target\_mc:MovieClip) {  
progressBar\_mc.bar\_mc.\_xscale = 0;  
}

// increase the width (xscale) of the bar as the file loads  
mclListener.onLoadProgress = function(target\_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {  
progressBar\_mc.bar\_mc.\_xscale = Math.round(bytesLoaded/bytesTotal\*100);  
// Make sure the clip being loaded doesn’t play until it is fully loaded.  
// If you want content to stream as it loads remove the following 3 lines  
tellTarget(\_root.img\_project.img\_holder){  
stop();  
}  
}

// once the file has loaded, remove the progress bar from the stage  
mclListener.onLoadComplete = function(target\_mc:MovieClip) {  
progressBar\_mc.removeMovieClip();  
// Plays the loaded clip once it’s fully loaded.  
// If you want content to stream as it loads remove the following 3 lines  
tellTarget(\_root.img\_project.img\_holder){  
play();  
}  
}

////////////////////////////////////////////////////////////////////// ///////////////////

// Load the project file onto the stage by loading it into a movieClip (which in this case  
// is inside another one img\_project \> img\_holder.

var image\_mcl:MovieClipLoader = new MovieClipLoader();  
image\_mcl.addListener(mclListener);

// load the clip onto the stage into a movieClip  
image\_mcl.loadClip(\_root.imageFolder + \_root.filesArray[arrayNumber], img\_project.img\_holder);

// Populate the dynamic text fields on the main stage with the project title & description  
\_root.prj\_name = \_root.namesArray[arrayNumber];  
\_root.prj\_description = \_root.descriptionsArray[arrayNumber];

// if the URL is present for this project, populate & show the link  
if(\_root.linksArray[arrayNumber] != “”) {  
\_root.btn\_link.webAddress = \_root.linksArray[arrayNumber];  
\_root.btn\_link.\_visible = 1;  
} else {  
\_root.btn\_link.\_visible = 0;  
}

// Reset the last button  
tellTarget("\_root.btn\_projects" + \_root.curButton){  
gotoAndPlay(1);  
}

// Replace the current button variable with this projects id/number  
\_root.curButton = arrayNumber;  
}

stop();

Any thoughts guys? even just pointers for where to go about getting started would be massively appreciated.  
kind regards D
