I have made an XML portfolio, bastardising a few tutorials together. One of these was the one on kirupa actually. Basically each portfolio item has three images (which slideshow), description and title (which is also the button to load img and description)
I need to load the first item in the xml automatically on start-up, however, the code I have now the first item only loads when you click the first menu item…The code is below if you are interested. I tried to create a loadFirstItem function but it doesnt seem to work…any ideas? thanks
// 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 -> menuitems -> child nodes array
for (var i=0; i<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;
item_mc.main_btn.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;
imagetextbox_txt.text=this.firstitem_txt;
imageHolder.morphContainer.loadMovie(imagetextbox_txt.text);
imageHolder.gotoAndPlay(1);
}
function fadeOutAndBack(){
imageHolder.alphaTo(0,1,“linear”);
imageHolder.onTweenComplete=function(){
if (imageHolder.alpha<1){
imageHolder.alphaTo(100,1,"linear");
}
}
}
stop();