getURL from XML, PLEASE HELP

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:

 
<?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:

ok, first you have to pass your xml to flash
this tutorial can tell you how:
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);
}

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

Dulcinea can you help?

ppplllllllllleeeeeeeaaaassssssseeeeeeeeee

someone else???

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

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);
}

Thank you very much naderslim :slight_smile:

you helped a lot

my final Action Script

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 **

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.

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)…

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?

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…