Hi,
I have been at a loss the past couple days and am in need of some assistance.
I have an XML document that has 3 person nodes, each have 2 nested elements called image and bio. What I am trying to accomplish is this, when a user clicks any of the 3 images it would display the appropriate bio in a text field on the stage.
As it is now, when I click any of the images it loads all the bios into the outputTxt text field on the stage. Below is what I have been able to do so far.
XML:
<people>
<person>
<image>assets/people01.png</image>
<bio>Description of person 1.</bio>
</person>
<person>
<image>assets/people02.png</image>
<bio>Description of person 2.</bio>
</person>
<person>
<image>assets/people03.png</image>
<bio>Description of person 3.</bio>
</person>
</people>
Actionscript File:
package
{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
public class People extends Sprite
{
private var xmlLoader:URLLoader;
private var xmlData:XML;
private var imgLoader:Loader;
private var clip:Sprite;
private var img:int = 0;
public function People()
{
xmlLoader = new URLLoader();
xmlLoader.load(new URLRequest("people.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
}
private function xmlLoaded(e:Event):void
{
xmlData = new XML(e.target.data);
loadImage();
}
private function loadImage():void
{
imgLoader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.INIT, imageLoaded);
imgLoader.load(new URLRequest(String(xmlData.person.image[img])));
img++;
}
private function imageLoaded(e:Event):void
{
clip = new Sprite();
clip.addChild(imgLoader.content);
clip.x = this.width;
addChild(clip);
clip.addEventListener(MouseEvent.CLICK, onClick);
if (img < xmlData.person.length())
{
loadImage();
}
}
private function onClick(e:MouseEvent):void
{
outputTxt.text = "";
outputTxt.text = String(xmlData.person.bio);
}
}
}
Thanks