# Help with xml please!

**URL:** <https://forum.kirupa.com/t/help-with-xml-please/260754>\
**Category:** flash\
**Created:** [May 19, 2008, 4:32pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754 "2008-05-19T16:32:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gvp16](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@gvp16](https://forum.kirupa.com/u/gvp16)\
**Post date:** [May 19, 2008, 4:32pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/1 "2008-05-19T16:32:36Z")

</div>

i have a bit of code that gets information from an xml file and loads it into a movie clip that i made. this works great for one result, but i want it to keep going so it duplicates the movie clip and brings out the other results. so far ive been able to duplicate the movie clip and place it at x & y co ords coming from the xml. but the rest of the information isnt coming through. any help would be great.

This is the code i have at the moment.  
myXML = new XML();  
myXML.ignoreWhite = true;  
myXML.onLoad = function(){  
imageList = this.firstChild.childNodes;  
showImages(imageList);  
}  
myXML.load(“gallery1.xml”);

function showImages(list:Array){

for(i=0;i\<list.length;i++){  
imageFile = list\*.attributes.url;  
nametxt = list\*.attributes.title;  
phonetxt = list\*.attributes.phone;  
yval = list\*.attributes.yval;  
xval = list\*.attributes.xval;

info.name\_txt.text = nametxt;  
info.address\_txt.text = address;  
info.phone\_txt.text = phonetxt;

info.picture.loadMovie(imageFile);  
info.\_x = xval;  
info.\_y = yval;  
trace(nametxt);

info.duplicateMovieClip(“info\_”+i, i+1);  
}  
}

Thanks

gvp16

---

<div class="post-metadata">

**Author:** ![Ikinsey](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Ikinsey](https://forum.kirupa.com/u/Ikinsey)\
**Post date:** [May 19, 2008, 5:51pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/2 "2008-05-19T17:51:32Z")

</div>

You really shouldnt be rolling this way in AS3.

Use the E4X syntax the Adobe Devs have blessed you with.

Gimme the structure of the XML and i’ll show you how to E4X reference that puppy.

---

<div class="post-metadata">

**Author:** ![gvp16](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@gvp16](https://forum.kirupa.com/u/gvp16)\
**Post date:** [May 19, 2008, 7:12pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/3 "2008-05-19T19:12:28Z")

</div>

[quote=Ikinsey;2328249]You really shouldnt be rolling this way in AS3.

Use the E4X syntax the Adobe Devs have blessed you with.

Gimme the structure of the XML and i’ll show you how to E4X reference that puppy.[/quote]

ive never heard of E4X, ive only just started using XML and dont know much about it.  
this is the xml im using.

\<gallery\>  
\<image url=“[http://www.gvperkins.com/images/glyn.jpg](http://www.gvperkins.com/images/glyn.jpg)” title=“Glynneath” phone=“11111111111” xval=“290” yval=“90”/\>  
\<image url=“[http://www.gvperkins.com/images/swan.jpg](http://www.gvperkins.com/images/swan.jpg)” title=“Swansea” phone=“00000000000” xval=“50” yval=“150”/\>  
\</gallery\>

Thanks.

---

<div class="post-metadata">

**Author:** ![Ikinsey](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Ikinsey](https://forum.kirupa.com/u/Ikinsey)\
**Post date:** [May 20, 2008, 1:30am UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/4 "2008-05-20T01:30:04Z")

</div>

E4X is a way of operating on and sifting through XML with simple syntax.  
You should go through your XML as follows:

```auto

//the .. in myXML..image means find all image nodes in MyXML (regardless of how nested)
//this for each loop will go through each image node
for each(var image:XMLNode in myXML..image)
{
     //DO STUFF HERE on each image node
     //use image.@attributeName to access the attributes of the node 
     //(ie: image.@xval will get the value of xval for this node).
}

```

---

<div class="post-metadata">

**Author:** ![gvp16](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@gvp16](https://forum.kirupa.com/u/gvp16)\
**Post date:** [May 20, 2008, 4:32pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/5 "2008-05-20T16:32:48Z")

</div>

sorry but i havent got a clue what to do with that, wot ive got for the xml works fine, its the flash thats giving me probs, however ive figured out what i need to do, just dont know how to do it. (see below).

myXML = new XML();  
myXML.ignoreWhite = true;  
myXML.onLoad = function(){  
imageList = this.firstChild.childNodes;  
showImages(imageList);  
}  
myXML.load(“gallery1.xml”);

function showImages(list:Array){

for(i=0;i\<list.length;i++){  
imageFile = list\*.attributes.url;  
nametxt = list\*.attributes.title;  
phonetxt = list\*.attributes.phone;  
yval = list\*.attributes.yval;  
xval = list\*.attributes.xval;

info.duplicateMovieClip(“info\_”+i, i+1); [COLOR=red]on this line is the variable ’ i ’ [/COLOR]  
info.name\_txt.text = nametxt; [COLOR=red]------ what i need to do is add the variable i to this instance name, making it info\_1 then info\_2 etc…[/COLOR]  
info.address\_txt.text = address; [COLOR=red]simply adding it, eg info+i doesnt seem to work Ⓜ[/COLOR]  
info.phone\_txt.text = phonetxt;

info.picture.loadMovie(imageFile);  
info.\_x = xval;  
info.\_y = yval;  
trace(nametxt);

}  
}

BTW im using action script 2.

---

<div class="post-metadata">

**Author:** ![Ikinsey](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Ikinsey](https://forum.kirupa.com/u/Ikinsey)\
**Post date:** [May 20, 2008, 4:57pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/6 "2008-05-20T16:57:33Z")

</div>

> BTW im using action script 2.

Well, there’s your problem.

---

<div class="post-metadata">

**Author:** ![Ikinsey](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@Ikinsey](https://forum.kirupa.com/u/Ikinsey)\
**Post date:** [May 20, 2008, 5:00pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/7 "2008-05-20T17:00:36Z")

</div>

Ha, but I think this might help you:

In AS2 the syntax this[“info\_”+i] allows you to do dynamic references. Any combination of  
parent[childInstanceName:String] works.

---

<div class="post-metadata">

**Author:** ![gvp16](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@gvp16](https://forum.kirupa.com/u/gvp16)\
**Post date:** [May 21, 2008, 8:59pm UTC](https://forum.kirupa.com/t/help-with-xml-please/260754/8 "2008-05-21T20:59:45Z")

</div>

ye thanks, sorted it now.
