External links read from XML file in Flsah
I was wondering how you use Actionscript 2, to read a URL/web address in a XML file and when you click a button, or an icon, you are then taken to a page specified in the XML document?
Hope you can help, and if you need more det开发者_运维问答ails don't hesitate to ask.
Snakespan
Your method could be right, but my XML and Flash is a little different to the example you gave, as I have individual icons on a carousel, and I want each one to have a different external link, so my XML is something like:
<icons>
<icon image="icon1.jpg" tooltip="Ramis Assets" url="www.mysite.com" /></icon>
</icon>
and my Flash is something like:
xml.onLoad = function()
{
var nodes = this.firstChild.childNodes;
numOfItems = nodes.length;
for(var i=0;i<numOfItems;i++)
{
var t = home.attachMovie("item","item"+i,i+1);
t.angle = i * ((Math.PI*2)/numOfItems);
t.onEnterFrame = mover;
t.toolText = nodes[i].attributes.tooltip;
t.url = nodes[i].attributes.url;
t.icon.inner.loadMovie(nodes[i].attributes.image);
t.r.inner.loadMovie(nodes[i].attributes.image);
t.icon.onRollOver = over;
t.icon.onRollOut = out;
t.icon.onRelease = released;
}
}
but of course this could be wrong, as I don't set up my function as a success/failure Boolean. Is there a way I could modify this method (or yours) so that I could get a handle on the individual icon and then when I click, it takes me to a site?
Hope you can help,
Snakespan.
I add another answer based on your code.
function released() { gotoURL(this.link, "_blank"); }
I think you should call the 'url' property 'link' as the url is reserved by AS. Just in case.
Hope this is it, Rob
/////////////////////
Hi,
Here is a quick example for loading and parsing links from an external xml file:
XML file (saved as links.xml):
<?xml version="1.0" encoding="utf-8" ?>
<links>
<link><![CDATA[http://heartcode.robertpataki.com]]></link>
<link><![CDATA[http://www.adobe.com]]></link>
<link><![CDATA[http://www.youtube.com]]></link>
</links>
AS (I put the script on the first frame in a new fla document and saved it as links.fla):
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = parseXML;
xml.load("links.xml");
var extLinks:Array = new Array();
function parseXML(success:Boolean):Void
{
if(success)
{
var i:Number = 0;
var l:Number = xml.firstChild.childNodes.length;
while(i<l)
{
extLinks[i] = xml.firstChild.childNodes[i].firstChild.nodeValue;
++i;
}
trace(extLinks);
}
else
{
trace("Could not load the xml file.");
}
};
When you publish the Flash document you will see it traces the links that are loaded from the XML file.
I hope this is what you seek for, Rob
精彩评论