# Struck with load as3 with multiple xml files

**URL:** https://forum.kirupa.com/t/struck-with-load-as3-with-multiple-xml-files/332594
**Category:** flash
**Created:** [August 8, 2014, 11:12am UTC](https://forum.kirupa.com/t/struck-with-load-as3-with-multiple-xml-files/332594 "2014-08-08T11:12:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![boopathiraj](https://avatars.discourse-cdn.com/v4/letter/b/c67d28/32.png) [@boopathiraj](https://forum.kirupa.com/u/boopathiraj)
#### Post date: [August 8, 2014, 11:12am UTC](https://forum.kirupa.com/t/struck-with-load-as3-with-multiple-xml-files/332594/1 "2014-08-08T11:12:40Z")

</div>

Hi guys,  
Im trying new website with the help of AS3 with XML.  
I cannot merge 2 AS3 files into single file. Both as3 contains XML files. If i added multiple layers for each as3 it shows lot of errors … Here is my code plz help me to clear this.  
**MENU.fla**

// 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, vertical) {  
// 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&lt;node_xml.childNodes.length; i++) {
    // movieclip for each menu item
    curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
    if(vertical)
    {
    curr_item._x = x+ i*curr_item._width;
    curr_item._y = y ;
    }else
    {
    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;
            var y = this._y - 95;
            GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml,false);
            // show a hover color
            var col = new Color(this.background);
            col.setRGB(0x000);
        };
    }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
            var col = new Color(this.background);
            col.setRGB(0x000);
        };
    }
    
    curr_item.onRollOut = curr_item.onDragOut = function(){
        // restore color
        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,true);  
// 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.gotoURL = function(urlVar){  
getURL(urlVar, “\_blank”);  
};  
Actions.message = function(msg){  
message\_txt.text = msg;  
};  
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(100, 600, 0, this);  
message\_txt.text = “message area”;  
}else{  
message\_txt.text = “error: XML not successfully loaded”;  
}  
};  
// load first XML menu  
menu\_xml.load(“menu1.xml”);

[HR][/HR]  
**Menu1.xml**  
\<menu name=“example”\>

```
&lt;item name="Our Philosophy" /&gt;
&lt;item name="About" /&gt;
&lt;menu name="Projects"&gt;
        &lt;item name="Proposed Project"/&gt;
        &lt;item name="Ongoing Project"/&gt;
        &lt;item name="Completed Project"/&gt;
        &lt;/menu&gt;
            &lt;item name="Key People"/&gt;
            &lt;item name="Testimonials"/&gt;
            &lt;item name="Contact Us"/&gt;

```

\</menu\>

[HR][/HR]  
**slideshow.fla**  
import flash.net.URLLoader;  
import flash.net.URLRequest;  
import flash.events.Event;  
import flash.display.Loader;  
import flash.utils.Timer;  
import flash.events.TimerEvent;  
import fl.transitions._;  
import fl.transitions.easing._;  
import flash.events.MouseEvent;

///\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*///

// declare variables  
var xmlData:XML;  
var xmlLoader:URLLoader = new URLLoader();  
var picLoader:Loader = new Loader();  
var picArray:Array = new Array();  
var titleArray:Array = new Array();  
var numberOfPics:int;  
var currentPic:Number =0;  
var myMusicClip:String;  
var delay:Number;

///\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*///

//Process XML Data  
xmlLoader.load(new URLRequest(“slideshow.xml”));  
xmlLoader.addEventListener(Event.COMPLETE, processXML);  
function processXML(event:Event):void{

```
xmlData = new XML(event.target.data);
/*trace(xmlData);*/
numberOfPics=xmlData.photolist.photo.length();
delay=xmlData.timer.text();
loadArrays();
loadImages();

```

function loadArrays()  
{  
for (var i:int=0; i\<numberOfPics ; i++)  
{  
picArray.push(xmlData.photolist.photo\*.@path);  
titleArray.push(xmlData.photolist.photo\*.@title);  
}  
}

///\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*///  
// load images

```
            function loadImages(){                    
            var myURLRequest:URLRequest = new URLRequest(picArray[currentPic]);
            picLoader.load(myURLRequest);
            picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completehandler)
            }

```

///\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*///

// display loaded Images

```
function completehandler(event:Event)
{
addChildAt(picLoader,0);
picLoader.x=6;
picLoader.y = 4.5;
}                
var myTimer:Timer = new Timer(delay);
myTimer.start();                
myTimer.addEventListener(TimerEvent.TIMER, changeImage);
function changeImage(event:TimerEvent)
{
    if(currentPic&lt;numberOfPics-1){currentPic++;loadImages()}                
    else{currentPic=0;loadImages()}                
}

```

}  
[HR][/HR]  
**slideshow.xml**  
\<?xml version=“1.0” encoding=“utf-8”?\>  
\<slideshow\>  
\<photolist\>  
\<photo path=“images/image1.jpg” title=“Barbecued Chicken” /\>  
\<photo path=“images/image2.jpg” title=“Bread and Rolls” /\>

```
&lt;/photolist&gt;
&lt;audio&gt;
    &lt;musicclip path="audio/soothing_music.mp3"/&gt;
&lt;/audio&gt;
&lt;timer&gt;4000&lt;/timer&gt;

```

\</slideshow\>  
[HR][/HR]Please help to combine this,
