# getURL from XML, PLEASE HELP

**URL:** <https://forum.kirupa.com/t/geturl-from-xml-please-help/61151>\
**Category:** flash\
**Created:** [August 16, 2004, 3:02pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151 "2004-08-16T15:02:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![uxte](https://avatars.discourse-cdn.com/v4/letter/u/278dde/32.png) [@uxte](https://forum.kirupa.com/u/uxte)\
**Post date:** [August 16, 2004, 3:02pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/1 "2004-08-16T15:02:13Z")

</div>

Hi everyone,

I’m still a newbie in flash development so I need a little help from anyone, please…

what i want to do is:

assign an action to a button that will **getURL** from a XML file (this XML being dinamically updated via PHP) from the child subnode: **\<link\>**

**my XML:**

```auto
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data[
<!ELEMENT title (comments, image, link)>
<!ATTLIST title name CDATA #REQUIRED>
<!ELEMENT comments (#PCDATA)>
<!ELEMENT image (#PCDATA)>
<!ELEMENT link (#PCDATA)>
]>
<data>
<title name="Portégè ">
<comments>1500,00 €</comments>
<image>/prod_img/r100.jpg</image>
<link>info.php?id=60</link>
</title>
<title name="Título 111">
<comments>0,00 €</comments>
<image>image1.jpg</image>
<link>info.php?id=60</link>
</title>
<title name="Título 2">
<comments>0,00 €</comments>
<image>image1.jpg</image>
<link>info.php?id=60</link>
</title>
<title name="Título 3">
<comments>0,00 €</comments>
<image>image1.jpg</image>
<link>info.php?id=60</link>
</title>
<title name="Título 4">
<comments>0,00 €</comments>
<image>image1.jpg</image>
<link>info.php?id=60</link>
</title>
<title name="Título 5">
<comments>0,00 €</comments>
<image>image1.jpg</image>
<link>info.php?id=60</link>
</title>
</data>

```

Can anyone help?

I need the AS for this to work, please :puzzled:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 17, 2004, 12:44am UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/2 "2004-08-17T00:44:02Z")

</div>

ok, first you have to pass your xml to flash  
this tutorial can tell you how:  
[http://www.kirupa.com/developer/actionscript/xmldataflash.htm](http://www.kirupa.com/developer/actionscript/xmldataflash.htm)  
then, the path you will use to get your link data cuold be:  
yourURL = yourXML.firstChild.childNodes[0].lastChild.firstChild.nodevalue;  
then, put in a button:  
on(release){  
getURL(yourURL);  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 18, 2004, 3:58pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/3 "2004-08-18T15:58:52Z")

</div>

Thank you **Dulcinea**

sorry but i’m no expert on this code stuff, so…

where should I put the path: **yourURL = yourXML.firstChild.childNodes[0].lastChild.firstChild.nodevalue;** in the flash movie? so that the button get it?

Is this a dum question?

thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 20, 2004, 12:46am UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/4 "2004-08-20T00:46:24Z")

</div>

**Dulcinea** can you help?

ppplllllllllleeeeeeeaaaassssssseeeeeeeeee

someone else???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 20, 2004, 12:12pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/5 "2004-08-20T12:12:00Z")

</div>

Put it straight after the section that loads in your XML and processes it’s contents

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 20, 2004, 12:59pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/6 "2004-08-20T12:59:05Z")

</div>

in the root timeline of the main movie, on the same frame number that the button resides, put this code:

myXml = new XML();

myXml.onLoad = function(success){  
if(success){  
\_root.myUrl = this.firstChild.childNodes[0].lastChild.firstChild.nodevalue;  
// whatever other node values you wish to bind can be put here  
//or you could redirect to another function to handle it  
}  
}

myXml.load(“myxmlsource.php”);

On your button you would then put

on (release) {

getURL(\_root.myUrl);  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 21, 2004, 5:52pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/7 "2004-08-21T17:52:38Z")

</div>

Thank you very much **naderslim** 🙂

you helped a lot

**my final Action Script**

```auto
myXml = new XML();
myXML.ignoreWhite = true;
myXML.load("destaques.xml");
myXML.ref = this;
myXml.onLoad = function(success) {
	if (success) {
		_root.firstUrl = this.firstChild.childNodes[0].lastChild.firstChild.nodevalue;
		_root.secondUrl = this.firstChild.childNodes[1].lastChild.firstChild.nodevalue;
		_root.thirdUrl = this.firstChild.childNodes[2].lastChild.firstChild.nodevalue;
		_root.fourthUrl = this.firstChild.childNodes[3].lastChild.firstChild.nodevalue;
		_root.fifthUrl = this.firstChild.childNodes[4].lastChild.firstChild.nodevalue;
		_root.sixthUrl = this.firstChild.childNodes[5].lastChild.firstChild.nodevalue;
	}
};

```

**the AS for the first button**

on (release) {  
getURL(\_root.firstUrl, “\_self”);  
}

\*\*And everything works well \>\> [you can see it here](http://teste.terazone.pt/destaques/destaques_xml.html) \*\*

**One last problem** that I have is that I need the data file to be called destaques\*\*.php\*\* instead of destaques\*\*.xml\*\* for the data base to recognize it but when I change it in the **AS** aswell as in the\*\* XML file name\*\* the flash movie seems to have trouble reading it. I have tested it locally and it works fine, but when online… doesn’t

Why is that? Can anyone help?

Thank you all that took the time to answer.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 21, 2004, 6:00pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/8 "2004-08-21T18:00:46Z")

</div>

Hi uxte,

you cannot rename your xml file name to a php extension without the file actually being a php file. You must create a php file that posts (a string containing your xml) back to your flash file. Then you can specify xmlobj.load(myxmldata.php)…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 25, 2004, 4:35pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/9 "2004-08-25T16:35:44Z")

</div>

> you cannot rename your xml file name to a php extension without the file actually being a php file. You must create a php file that posts (a string containing your xml) back to your flash file. Then you can specify xmlobj.load(myxmldata.php)…

well so, why it works offline?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 25, 2004, 4:38pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/10 "2004-08-25T16:38:50Z")

</div>

offline, flash attempts to read loaded files as text. online your server is treating the file like a php file due to the extension…it expects a php declaration within your file…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 12:07pm UTC](https://forum.kirupa.com/t/geturl-from-xml-please-help/61151/11 "2004-08-26T12:07:10Z")

</div>

I went through this tutorial and i pretty much understood how to extract data from nodes.

I got a few questions though. (I’m new to flash and AS)

How do you apply a getURL to a text? if i use “getURL” as such, it opens the page without being clicked on. And if i use onRelease, it’ll cause an error because i don’t have any buttons.

```auto
function loadXML(loaded) { 
if (loaded) { 
_root.inventor = this.firstChild.childNodes[0].childNodes[8].childNodes[2].firstChild.nodeValue; 
_root.comments = this.firstChild.childNodes[0].childNodes[8].childNodes[0].firstChild.nodeValue;
_root.link = this.firstChild.childNodes[0].childNodes[8].childNodes[2].firstChild.nodeValue;
name_txt.text = _root.inventor; 
comment_txt.text = _root.comments;
[COLOR=Red]**getURL(_root.link);**[/COLOR]
} else { 
  trace("file not loaded!"); 
} 
} 
xmlData = new XML(); 
xmlData.ignoreWhite = true; 
xmlData.onLoad = loadXML; 
xmlData.load("http://news.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss091.xml");

```

I’m used to java so i can pick up some things fast. If thats used in the AS template from the tutorial it works pretty well except that the link opens up without it being clicked on. I’d like to learn how to link a piece of text.

Secondly, from the RSS there are several such links, how would i go about a for loop? or an If statement? Could i do something like “if nodeName = URL” do something?

I’m just curious thats all. Could someone please explain?

Cheers
