# Auto-load first item in xml?

**URL:** <https://forum.kirupa.com/t/auto-load-first-item-in-xml/238004>\
**Category:** Uncategorized\
**Created:** [September 6, 2007, 8:48am UTC](https://forum.kirupa.com/t/auto-load-first-item-in-xml/238004 "2007-09-06T08:48:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpixel](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@jpixel](https://forum.kirupa.com/u/jpixel)\
**Post date:** [September 6, 2007, 8:48am UTC](https://forum.kirupa.com/t/auto-load-first-item-in-xml/238004/1 "2007-09-06T08:48:00Z")

</div>

im simply trying to load in the first xml item on start-up. The xml has title, description and image paths…heres the code for those who are interested:

imagetextbox\_txt.\_visible=false;  
imagetextbox2\_txt.\_visible=false;  
imagetextbox3\_txt.\_visible=false;

// define basic variables for setting up the menu  
var item\_spacing = 16; // how far menu items are spaced veritcally  
var item\_count = 0; // counts menu items as they are added from the XML

// CreateMenu creates a menu based on the XML object passed.  
// It loops through all the items with a for loop adding clips to the menu\_mc  
// movieclip on the timeline, defining the appropriate text where needed  
function CreateMenu(menu\_xml){

```
// start with the first item in the XML
var items = menu_xml.firstChild.firstChild.childNodes; // menu -&gt; menuitems -&gt; child nodes array
for (var i=0; i&lt;items.length; i++) {
    // only continue if the type of this item is a squirrel
    if (items*.attributes.type == "advertising") { 
        // create variables for our elements
        var itemtitle = items*.firstChild; // same as items*.childNodes[0]
        var description = items*.childNodes[1]; // second child node
        var imagepath = items*.childNodes[2]; // third child node
        var imagepath2 = items*.childNodes[3]; // third child node
        var imagepath3 = items*.childNodes[4]; // third child node
        
        var firstitem = items[0].childNodes[2]; // first item
        
        // Create a menu item movie clip in the menu_mc instance on the main timeline
        // for each item element offsetting each additional further down the screen
        var item_mc = menu_mc.attachMovie("menu_item","item"+item_count, item_count);
        item_mc._y = item_count * item_spacing;
        item_count++;
        
        
        // assign text using nodeValue to get the text
        // from the text nodes and CDATA sections
        item_mc.textclip.species_txt.text = itemtitle.firstChild.nodeValue;
        item_mc.main_btn.location_text = description.firstChild.nodeValue;
        
        item_mc.main_btn.imagepath_txt = imagepath.firstChild.nodeValue;
        item_mc.main_btn.imagepath2_txt = imagepath2.firstChild.nodeValue;
        item_mc.main_btn.imagepath3_txt = imagepath3.firstChild.nodeValue;
        
        firstitem_txt = firstitem.firstChild.nodeValue;
        
        trace (imagepath.firstChild.nodeValue);
        
        // set the onRelease of the item button to the DisplayInfo function
        item_mc.main_btn.onRelease = DisplayInfo;
        
        

        
        
        
        
    }
}

```

}

// manage XML  
// create new XML object instance, remembering to ignore white space  
var portfolio\_xml = new XML();  
portfolio\_xml.ignoreWhite = true;  
// define an onLoad to create our location menu when the XML has successfully loaded.  
portfolio\_xml.onLoad = function(success){  
if (success) CreateMenu(this);  
else trace(“Error loading XML file”); // no success? trace error (wont be seen on web)  
}  
// load the xml file!  
portfolio\_xml.load(“portfolio.xml”);

// DisplayInfo is used when an item is pressed  
// it hides the menu\_mc (and the buttons) and shows the  
// infobox\_mc, assigning the text of the selected button  
// to the textbox within.  
function DisplayInfo(){

```
 imageHolder.gotoAndPlay(1);
fadeOutAndBack();
 
menu_mc._visible = true;
infobox_mc._visible = true;
infobox_mc.content_txt.text = this.location_text;

```

imagetextbox\_txt.text=this.imagepath\_txt;  
imagetextbox2\_txt.text=this.imagepath2\_txt;  
imagetextbox3\_txt.text=this.imagepath3\_txt;  
//  
imagetextbox\_txt.\_visible=false;  
imagetextbox2\_txt.\_visible=false;  
imagetextbox3\_txt.\_visible=false;

imageHolder.morphContainer.loadMovie(imagetextbox\_txt.text);  
imageHolder.morphContainer2.loadMovie(imagetextbox2\_txt.text);  
imageHolder.morphContainer3.loadMovie(imagetextbox3\_txt.text);

bannerMC.\_alpha=0;

}

function loadFirstItem(){

menu\_mc.\_visible = true;  
infobox\_mc.\_visible = true;  
infobox\_mc.content\_txt.text = this.location\_text;  
imagetextboxfirst\_txt.text=firstitem\_txt;  
imageHolder.morphContainer.loadMovie(imagetextboxfirst\_txt.text);  
imageHolder.gotoAndPlay(1);

}

//loadFirstItem();

function fadeOutAndBack(){  
imageHolder.alphaTo(0,1,“linear”);

```
     imageHolder.onTweenComplete=function(){
          if (imageHolder.alpha&lt;1){
         imageHolder.alphaTo(100,1,"linear");
     }
     
 }

```

}

stop();
