# Passing XML data to LoadVars

**URL:** <https://forum.kirupa.com/t/passing-xml-data-to-loadvars/197501>\
**Category:** programming\
**Created:** [August 16, 2006, 9:40pm UTC](https://forum.kirupa.com/t/passing-xml-data-to-loadvars/197501 "2006-08-16T21:40:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalamus](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@thalamus](https://forum.kirupa.com/u/thalamus)\
**Post date:** [August 16, 2006, 9:40pm UTC](https://forum.kirupa.com/t/passing-xml-data-to-loadvars/197501/1 "2006-08-16T21:40:11Z")

</div>

[SIZE=1]Hello:[/SIZE]

[SIZE=1]I am working with XML structure similar to the following:[/SIZE]

[SIZE=1]\<inventory\>[/SIZE]  
[SIZE=1]\<item num=“1” aname1=“John” aname2=“Doe” /\>[/SIZE]  
[SIZE=1]\<item num=“2” aname1=“Frank” aname2=“Smith” /\>[/SIZE]  
[SIZE=1]\</inventory\>[/SIZE]

[SIZE=1]I have defined the var aname2 on the main timeline as follows:[/SIZE]  
[SIZE=1]var inv = inventory\_xml.firstChild;[/SIZE]  
[SIZE=1]var catalogitem = inv.childNodes;[/SIZE]  
[SIZE=1]var aname2 = catalogitem\*.attributes.aname2;[/SIZE]

[SIZE=1]I have also on the main Timeline a mc which holds a dynamic text field called [/SIZE][SIZE=1]statement\_txt.[/SIZE]

[SIZE=1]I am trying to use LoadVars to load a text variable named “statement” from a text file[/SIZE]  
[SIZE=1]which is named “stmt\_”+aname2+".txt" into statement\_txt.[/SIZE]

[SIZE=1]The following example just loads the John Doe text file into the mc:[/SIZE]

[SIZE=1]// Load text from artist statement txt file and assign it to statement\_txt[/SIZE]  
[SIZE=1]// while preserving HTML formatting within text variable[/SIZE]  
[SIZE=1]statement\_lv = new LoadVars();[/SIZE]  
[SIZE=1]statement\_lv.onLoad = onText;[/SIZE]  
[SIZE=1]statement\_lv.load("/statements/stmt\_Doe.txt");[/SIZE]  
[SIZE=1]function onText() {[/SIZE]  
[SIZE=1]statement\_txt.html = true;[/SIZE]  
[SIZE=1]statement\_txt.htmlText = statement\_lv.statement;[/SIZE]  
[SIZE=1]}[/SIZE]

[SIZE=1]I want to be able to change it so the word “Doe” in the filepath replaced with the variable aname2, so that:[/SIZE]

[SIZE=1]if(catalogitem\*.attributes.aname2 == “Doe”) { [/SIZE]

[SIZE=1]…then load variable named “statement” from filepath /statements/stmt\_Doe.txt, and:[/SIZE]

[SIZE=1][SIZE=1]if(catalogitem\*.attributes.aname2 == “Smith”) { [/SIZE]

[SIZE=1]…then load variable named “statement” from filepath /statements/stmt\_Smith.txt[/SIZE]

[/SIZE][SIZE=1]i tried something like:[/SIZE]

[SIZE=1]var a2 = “stmt\_”+aname2+".txt";[/SIZE]  
[SIZE=1]statement\_lv.load(a2);[/SIZE]

[SIZE=1]but it returned undefined.[/SIZE]

[SIZE=1]Any ideas? Thanks.[/SIZE]
