PDA

View Full Version : How to send text AND images to stage from xml?


mebabyme
02-15-2008, 02:19 PM
Hi,

I have been a 'squirrel finder' tutorial from kirupa.com (http://www.kirupa.com/web/xml/exampl...rrelfinder.htm) to try and create a fairly simple xml-fed flash interface. Basically, i need to have a list of architectural projects in a menu, and when each one is clicked the project info is loaded into a dynamic text field and a series of maybe 2 or 3 images are also sent to movie clips on the stage.

I've got as far as just displaying the text using the tutorial: http://beentheunseen.ae-hosting.com/projects.html

This is my xml file:

<?xml version="1.0" ?>
<menu>
<menuitems>
<item type="school">
<name>Chapin School</name>
<info>
<![CDATA[This school has been under development for many years...]]>
</info>
<image1>face.jpg</image1>
<image2>face2.jpg</image2>
<image3>face3.jpg</image3>
</item>
<item type="school">
<name>Molloy School</name>
<info>
<![CDATA[Our work with Molloy has been...]]>
</info>
<image1>molloy.jpg</image1>
<image2>molloy2.jpg</image2>
<image3>molloy3.jpg</image3>
</item>
<item type="school">
<name>Deerfield Academy</name>
<info>
<![CDATA[Text text text...]]>
</info>
<image1>deerfield.jpg</image1>
<image2>deerfield2.jpg</image2>
<image3>deerfield3.jpg</image3>
</item>
<item type="school">
<name>Canterbury School</name>
<info>
<![CDATA[Text text text...]]>
</info>
<image1>canterbury.jpg</image1>
<image2>canterbury2.jpg</image2>
<image3>canterbury3.jpg</image3>
</item>
</menuitems>
</menu>

And this is the AS code:

function DisplayInfo(){

infobox_mc._visible = true;
infobox_mc.content_txt.text = this.location_text;
}

var item_spacing = 18;
var item_count = 0;

function CreateMenu(menu_xml){

var items = menu_xml.firstChild.firstChild.childNodes;
for (var i=0; i<items.length; i++) {

if (items[i].attributes.type == "school") {

var species = items[i].firstChild;
var location = items[i].childNodes[1];

var item_mc = menu_mc.attachMovie("menu_item","item"+item_count, item_count);
item_mc._y = item_count * item_spacing;
item_count++;

item_mc.species_txt.text = species.firstChild.nodeValue;
item_mc.main_btn.location_text = location.firstChild.nodeValue;

item_mc.main_btn.onRelease = DisplayInfo;
}
}
}

var squirrel_xml = new XML();
squirrel_xml.ignoreWhite = true;

squirrel_xml.onLoad = function(success){
if (success) CreateMenu(this);
else trace("Error loading XML file");
}

squirrel_xml.load("projects.xml");

Unfortunately the code is still mildly squirrel themed, lol. Could anyone help me to incorporate a way to display the images specified in the XML file at the same time as the project information? I assume i need to make a couple of movie clips on the stage and send the file url information to them somehow. I've tried adding bits of script from a number of tutorials and forums, but i don't seem to be able to make it work...

Thanks!

Ben