-
XML URL Link in Flash
Hi, I am new to XML and am having a small problem in Flash. I have a number of buttons. Each of these buttons need to open up a different URL which is in a xml file (I have added only one button for now (banstead), as I wasn´t sure how to add more).
My XML:
<?xml version="1.0" encoding="utf-8"?>
<banstead targ="_self" href="http://www.marca.com" </banstead>
My AS:
weblinkXML = new XML();
weblinkXML.ignoreWhite = true;
weblinkXML.load("xml/counties.xml");
weblinkXML.onLoad = function (success)
{
var url = weblinkXML.firstChild.attributes.href;
banstead.onRelease = function ()
{
getURL(weblinkXML.url);
}
}
For some reason when I test the movie and click on the button it doesn´t open the URL I requested.
Appreciate any help
-
Hi,
I have now got it working. Turns out it was a XML format issue.
I do however have to add more buttons which link to other nodes within the XML file.
At the moment my xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<surrey>
<banstead href="http://www.marca.com"></banstead>
<epsom href="http://www.as.com"></epsom>
<staines href="http://www.as.com"></staines>
etc....
</surrey>
and this is my as:
weblinkXML = new XML();
weblinkXML.ignoreWhite = true;
weblinkXML.load("xml/counties.xml");
weblinkXML.onLoad = function (success)
{
var url = weblinkXML.firstChild.childNodes[0].attributes.href;
banstead_btn.onRelease = function ()
{
getURL(url);
}
}
As you can see, at the moment I am only referencing one button (banstead_btn), but I will eventually have an additional 8 or 9 buttons, all with different URLs. how do I do this?
-
If buttons are on main timeline, and named: banstead_btn, epsom_btn, staines_btn, etc
Code:
weblinkXML.onLoad = function(success) {
if (success) {
var len = weblinkXML.firstChild.childNodes.length;
for (var i = 0; i<len; i++) {
var buttonName = String(weblinkXML.firstChild.childNodes[i].nodeName+"_btn");
_root[buttonName].myurl = weblinkXML.firstChild.childNodes[i].attributes.href;
_root[buttonName].onRelease = function() {
getURL(this.myurl);
};
}
}
};
-
great, thanks loads for this. Saved me lots of hassle
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|