XML displaying data

I’m trying to set up a simple document. Loads portfolio info from an XML file and generates buttons based on the number of projects in the file. My frustration is I can’t figure out how to associate the record number of the XML file to the button. My goal is user clicks button 3, project 3 info shows, click button 1, project 1 shows, etc.

Thanks for any help or pointing me to a tutorial that can mend my brain.

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, showXML);
xmlLoader.load(new URLRequest("portfolio.xml"));
function showXML(e:Event):void {
	XML.ignoreWhitespace = true;
	var projects:XML = new XML(e.target.data);
	//trace(projects.project.length());
	var _container:container;
	var _containerX:Number = 345;
	var _containerY:Number = 300;
	var _containerA:Number = 100;
	for (var i:Number = 0; i < projects.project.length(); i++) {
		_container= new container();
		addChild(_container);
		_container.x = _containerX;
		_container.y = _containerY;
		_containerX += 35;
		type.text = projects.project*.type.text();
		p_kind.text = projects.project*.kind.text();
		project.text = projects.project*.project_name.text();
		client.text = projects.project*.client.text();
		var artwork:Loader = new Loader();
		port_image.addChild(artwork);
		artwork.load(new URLRequest("IMG/PORT/"+projects.project*.port_image));

		_container.addEventListener(MouseEvent.CLICK, traceThis);
		function traceThis(event:MouseEvent):void {
			trace(i); // ONLY DISPLAYS # FOR THE LAST RECORD
			// GOAL IS TO SHOW DATA RELATIVE TO BUTTON GENERATED
		}

	}

}

What you can do is have a button class with properties representing your project details
and then when you are parsing your xml file you can create buttons using new ButtonClass and set the properties of that class with info of your project.

here is some code
// parse xml
for (var i:Number = 0; i < projects.project.length(); i++) {
// your project name
var name:String = project*.name;
// your project contents
var contents:String = project*.contents;
// similarly add the remaining properties here and then create a ButtonClass object for each project by passing properties as arguments to button class consturctor.

var btn:ButtonClass = new ButtonClass(name, contents,…so on)

// now define the button class

import flash.display.*;

public class ButtonClass extends MovieClip
{
// class properties
private var name:String;
private var contents:String;

// constructor
public function ButtonClass(nam:String,con:String…)
{
this.name = nam;
this.con = contents;
… set the remaining
}
// Now add an Event listener for Button Click
addEventListener(MouseEvent.CLICK , onClick);

// when the button is clicked trace the content propert or use a textfield to display it
public function onClick(e:MouseEvent):void
{
trace(this.contents);
}
}

I hope this is making sense

[QUOTE=adnan794;2325230]I hope this is making sense[/QUOTE]

:slight_smile: No! But thanks. I see the word “class” and stick my head in the ground. I’m going to pick this apart and force myself to learn this. Thanks again.