Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create dynamic texfield for info in xml?

Status
Not open for further replies.

C0FFEE123

Programmer
Sep 1, 2008
44
NL
Hello,

I am currently using Actionscript with xml.
Now i want to create a dynamic textfield in actionscript for each part of info in the xml file.

I want to let the textfields created automaticly so i don't want to manual input the xml parts into the actionscript.

Here is the xml code:

Code:
<?xml version="1.0"?>
<Informatie>
  <Autos>
    <Auto>Toyota</Auto>
    <Shortd>Testje</Shortd>
    <Longd>Testje</Longd>
    <Prijs>4543</Prijs>
  </Autos>
  <Autos>
    <Auto>asd</Auto>
    <Shortd>asdf</Shortd>
    <Longd>as</Longd>
    <Prijs>3435</Prijs>
  </Autos>
</Informatie>

-------------------------------------
I am a progammer.... no realy.
 
Sorry for the long waiting.
Went on a short vacation. ^^
Only i can't upload the .fla file because i havn't got it online.

Here is the code in the .fla file:

Code:
function loadXML(loaded) {

if (loaded) {

_root.Informatie = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.Auto = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
name_txt.text = _root.Informatie;
comment_txt.text = _root.Auto;
} else {
  trace("file not loaded!");

}

}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("info.xml");

-------------------------------------
I am a progammer.... no realy.
 
Forget the above code i already figured out to get all of the xml data into flash.
Only need to get it into a dynamic textfield.
And i want to create the dynamic textfield in actionscript.
I believe the this.createTextField should do the trick only i don't know how to exactly use it.

XML code:
Code:
<?xml version="1.0"?>
<root-node>
<Auto merk="berlingo" sdescription="Dit is een test" ldescription="Dit is een langere test" prijs="123"> </Auto>
<Auto merk="Toyota" sdescription="Dit is een test2" ldescription="Dit is een langere tes2t" prijs="1232"> </Auto>
</root-node>

Flash code:
Code:
var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("info.xml");
myXML.onLoad = function(success) {
if (success) {
var myImage = myXML.firstChild.childNodes;
for (i=0; i<myImage.length; i++) {
var imageNumber = i+1;
var imageName = myImage[i].attributes.merk;
var imagesdescription = myImage[i].attributes.sdescription;
var imageldescription = myImage[i].attributes.ldescription;
var imageprijs = myImage[i].attributes.prijs;
}
}
};

-------------------------------------
I am a progammer.... no realy.
 
Alright i now have this:

Code:
var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("info.xml");
myXML.onLoad = function(success) {
if (success) {
var myImage = myXML.firstChild.childNodes;
for (i=0; i<myImage.length; i++) {
var imageNumber = i+1;
var imageName = myImage[i].attributes.merk;
var imagesdescription = myImage[i].attributes.sdescription;
var imageldescription = myImage[i].attributes.ldescription;
var imageprijs = myImage[i].attributes.prijs;
	// Create Text Field 
	    createTextField("tLabel", this.getNextHighestDepth(), 10, 10, 400, 200); 
        tLabel.html = true;
	tLabel.htmlText =imageName + " " + imagesdescription + " " + imageldescription + " " + imageprijs;
	tLabel.setTextFormat(tfFormatter);
}
}
};

		//Text Format
var tfFormatter:TextFormat = new TextFormat(); 
    tfFormatter.font = "Arial";
	tfFormatter.size = 14;

Only it shows only the second child of the xml.
I want it to show both and eventualy everything if there is more information in the xml.

-------------------------------------
I am a progammer.... no realy.
 
Alright now i've got this.
It makes several names for the textfields like tLabel0, tLabel1 enz.
Only now i want to show the xml data in the created textfields.
It only doesn't work, because i do tLabel.htmlText
I want to know how to i can make tLabel into tLabel0, tLabel1 enz.

Thanks

Code:

Code:
controleID = setInterval(interval, 5000);
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.load("info.xml");
myXML.onLoad = function(success) {
//	controleID = setInterval(interval, 100);
//	function interval() {
//	if(Key.isDown(Key.SPACE)){
//		success();\
	if(success){
		var myImage = myXML.firstChild.childNodes;
		//var myTextField = ("tLabel" + i);
		for (i=0; i<myImage.length; i++) {
			var h = 40;
			var imageNumber = i+1;
			var old = 10;
			var imageName 			= myImage[i].attributes.merk;
			var imagesdescription 	= myImage[i].attributes.sdescription;
			var imageldescription 	= myImage[i].attributes.ldescription;
			var imageprijs 			= myImage[i].attributes.prijs;
			 //Create Text Field 
			createTextField("tLabel" + i,this.getNextHighestDepth(),10,i * h,400,old += 40);
			tLabel.html = true;
			tLabel.htmlText = imageName+" "+imagesdescription+" "+imageldescription+" "+imageprijs;
			tLabel.setTextFormat(tfFormatter);
			trace(tLabel);
		}
	}
}
//Text Format
var tfFormatter:TextFormat = new TextFormat();
tfFormatter.font = "Arial";
tfFormatter.size = 14;

-------------------------------------
I am a progammer.... no realy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top