Creating a very simple XML-driven gallery
Hi, I'm learning XML in AS3 and I am having real trouble finding a resource that can help me learn how to build a very simple XML-driven picture gallery.
I am working in an FLA file with AS3, with a dynamic text field with the instance name "textfield". I also have a UILoader Component with the instance name "UILoaderComponent" and an XML file called "rootdir.xml".
I have an XML file in the following format.
<images>
<imagenames>
<name>image1</name>
<name>image2</name>
<name>image3</name>
<name>image4</name>
<name>image5</name>
</imagenames>
<imagepaths>
<path>image1.jpg</path>
<path>image2.jpg</path>
<path>image3.jpg</path>
<path>image4.jpg</path>
<path>image5.jpg</path>
</imagepaths>
</images>
I am using the following as my actionscript.
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("rootdir.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
parseImg(xmlData);
}
function parseImg(imgLoad:XML):void {
var imgChild:XMLList = imgLoad.images.children();
for each (var imgTrace:XML in imgChild) {
trace(imgTrace);
};
}
No matter which way I experiment, I always have poor results with my dynamic text, and every tutorial I've followed does not reproduce anything like the same returned data in "textfield" that it does with the trace command.
My objective is: I simply want to build a menu inside a textbox called "textfield" that lists images1-5, and when clicked, calls upon the relevant image. For instance: I load the file "rootdir.xml" into the file "index.fla". I call a function to parse the XML into a dynamic text box called "textfield". When image 2 is clicked on the textbox "textfield", it would call upon a function that would load into the UIComponent Loader "image2.jpg".
Are there any tutorials for this? I'm so confused as to why dynamic text operates so differently from the trace command. I'm not interested in doing a fancy menu bar with thumbnails, scrollbars and animations, I just want to learn the basics.
