Hi
Does anyone know how I could control a buttons link using xml? That way the link could be changed anytime without having to open the flash source file and re-export the movie.
I will appreciate it much
ciao
:-)
Printable View
Hi
Does anyone know how I could control a buttons link using xml? That way the link could be changed anytime without having to open the flash source file and re-export the movie.
I will appreciate it much
ciao
:-)
are you wanting to change a list of links?.. of just a single link attached to a single button?... if you need something like a list box populated through XML i can post a source file for you.. For an many child nodes as you have... it will attach a button from the library, populate the text and assign a link....
you would just use the value in that particular node as the value of the VAR in the getURL method.
example:
or wherever the node really is.Code:button1.onPress = function() {
getURL(xmlDocument.childNode[0].firstChild.nodeValue);
}
heres a quick example: (although Im not sure HOW your link is going to be set up..here I just used a textField to not only DISPLAY the value of the NODE.but use that value AS the URL to go to:
example:
Code:var myXML:XML = new XML("<Details><Username>(ip) R o l i e (ip) ~ (#)</Username><PSM>http://www.nike.com</PSM><Status>Online</Status></Details>");
trace("WHOLE XML: "+myXML);
/////
trace(newline);
////
//username node
trace("Full User Node: "+myXML.firstChild.childNodes[0]);
trace("User Node Name: "+myXML.firstChild.childNodes[0].nodeName);
trace("User Value: "+myXML.firstChild.childNodes[0].firstChild.nodeValue);
/////
trace(newline);
////
//psm node
trace("Full PSM Node: "+myXML.firstChild.childNodes[1]);
trace("PSM Node Name: "+myXML.firstChild.childNodes[1].nodeName);
trace("PSM Value: "+myXML.firstChild.childNodes[1].firstChild.nodeValue);
linkField_txt.text = myXML.firstChild.childNodes[1].firstChild.nodeValue;
var myformat:TextFormat = new TextFormat();
myformat.url = myXML.firstChild.childNodes[1].firstChild.nodeValue;
linkField_txt.setTextFormat(myformat);
Hi Whispers
I was thinking more of a situation like this:
1. I have created my buttons within flash.
2. The links for each of these buttons will be taken from an external xml file
That way, when I want to lets say disable a link, I could do that from the xml file or change the link easily.
As simple as that..
Will appreciate
use the code above... its the same no matter how you apply it..I just chose to output it a textField..and use THAT as the button/link..
now on your buttons you could have:Code:var myXML:XML = new XML("<links><link>http://www.nike.com</link><link>http://www.google.com</link><link>http://www.yahoo.com</link></links>");
trace("WHOLE XML: "+myXML);
/////
trace(newline);
////
//link1 node
trace("Full Link Node: "+myXML.firstChild.childNodes[0]);
trace("Link Node Name: "+myXML.firstChild.childNodes[0].nodeName);
trace("Link Value: "+myXML.firstChild.childNodes[0].firstChild.nodeValue);
link1 = myXML.firstChild.childNodes[0].firstChild.nodeValue;
/////
trace(newline);
////
//link2 node
trace("Full Link Node: "+myXML.firstChild.childNodes[1]);
trace("Link Node Name: "+myXML.firstChild.childNodes[1].nodeName);
trace("Link Value: "+myXML.firstChild.childNodes[1].firstChild.nodeValue);
link2 = myXML.firstChild.childNodes[1].firstChild.nodeValue
button1:
button2:Code:on(press) {
getURL(link1);
}
same as doing:Code:on(press) {
getURL(link2);
}
button1:
and this is exactly what I just posted before... unless I am missing something?Code:on(press) {
getURL(myXML.firstChild.childNodes[0].firstChild.nodeValue);
}
But whispers
according to the script it looks like the xml is embedded in the flash file.
How would I link what you have given me to an external xml file??
thanks, will appreciate
:-)
ahhhh..I see I didnt know you need to know how to LOAD the XML as well your first post gave me the impression you knew how already. basically you would use an XML Object...(same as a loadVar Object but for XML)...
this is how a basic XML object is created and used:
1.) to import an XML file...first you need to create an XML object to refer to your data..
2.) you then need to define the actions FLASH wll perform once the XML data "IS" loaded..
3.) you then need to make a call to actually try and LOAD the XML file.
so your code might be similar to this:Code:// create xml object (step1)
myXML = new XML();
// define actions to do once XML loads (step2)
myXML.onLoad = function(success) {
if (!success) {
trace("XMLfailed to load");
// plus any other actions you want to execute
}else {
trace("load was good");
// plus any other actions you want to execute
}
};
// call the actual XML file (step3)
myXML.load("whateverFile.xml");
Code:// create xml object (step1)
myXML = new XML();
// define actions to do once XML loads (step2)
myXML.onLoad = function(success) {
if (!success) {
trace("XMLfailed to load");
// plus any other actions you want to execute
}else {
trace("load was good");
link1 = myXML.firstChild.childNodes[0].firstChild.nodeValue;
link2 = myXML.firstChild.childNodes[1].firstChild.nodeValue;
}
};
// call the actual XML file (step3)
myXML.load("whateverFile.xml");
Hi,
I have tried this code and it doesent work for me - hope someone will help me find what im doing wrong...
I have 9 buttons in one flash (menu bar) and for that 9 buttons I need that they get links form xml file so links can be changed without flash.
I'm using flash mx
this is what my xml looks like
<menu>
<menu1>
<url>home.php</url>
<alt>Home</alt>
<title>Home</title>
</menu1>
<menu2>
<url>news.php</url>
<alt>News</alt>
<title>News</title>
</menu2>
<menu3>.... and so on.
I have tried with xml like in this example here
<links>
<url><![CDATA[home.php]]></url>
<url><![CDATA[news.php]]></url>...
and put code on each button
Button 1
on (release) {
myButton.onPress = function() {
getURL(urls[0].firstChild.nodeValue);
};
}
Button 2
on (release) {
myButton.onPress = function() {
getURL(urls[1].firstChild.nodeValue);
};
}
Button 3
... getURL(urls[2].firstChild.nodeValue... changing number after urls
but it doesent work - xml loads and when I test movie links show in output window but when I click buttons nothing happens.
If someone could help me I would be gratefull - and maybe advice what needs to be changed so I can use my xml...
Thanks
I think it is your button code/syntax.. ;)
you have an onRelease checking for an onPress function.. probably not gonna happen.
1.) is the code ON the buttons.. or in a FRAME?
2.) you do have button instance names for them...correct?
Thanks for replying - I think it also has something with flash mx - using as1 and I think this code is for as2... dont like coding - im more visual man...
1. I have 9 buttons on one layer and code is on each button
2. er... donno... probaly not...
Please help... :yikes:
lol..
ok..no problem.. we'll get it figured out.
sorry I missed you were using MX..
the code for your buttons should be the
on(press) {
//code / path to xml value goes here
}
syntax.
what is your code for parsing the XML into your movie?..
do you have a VAR (url[]) that is a shortcut to the url node/element??
you sure its correct?
are you using the XML code posted above?
that is for XM2004 and above....
I dont think MX let you strict type your vars yet..
if there is any in any of the code your using.
This is code from above I used for loading xml into flash
dont see any var thingies...Code:links_xml = new XML();
links_xml.load("menulink.xml");
links_xml.ignoreWhite = true;
links_xml.onLoad = function(success) {
if (success) {
urls = this.firstChild.childNodes;
for (i=0; i<urls.length; i++) {
trace(urls[i].firstChild.nodeValue);
}
} else {
trace("error loading xml");
}
};
Also I tried your code for button and it works but only if links are in same folder - like <url><![CDATA[menu.html]]></url> but if its <url><![CDATA[http://www.google.com]]></url> - outside link than it doesent work - i get message "cant find //C:/localfolder/www.google.com"
Also what I would need to change to use xml in format like this
Thanks for helping me!Code:<menu>
<menu1>
<url>home.php</url>
<alt>Home</alt>
<title>Home</title>
</menu1>
<menu2>
<url>news.php</url>
<alt>News</alt>
<title>News</title>
</menu2>
<menu3>...etc
I havent tested it..but it should work for your XML set-up..like you want.Code:links_xml = new XML();
links_xml.load("menulink.xml");
links_xml.ignoreWhite = true;
links_xml.onLoad = function(success) {
if (success) {
trace("XML: " + links_xml);
totalLinks = links_xml.firstChild.childNodes.length;
trace("TOTAL LINKS: " + totalLinks+newline);
for (i = 0; i < totalLinks; i++) {
trace("LINK " + i + " DETAILS:");
urlVar = links_xml.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
trace("URL: " + urlVar);
altVar = links_xml.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
trace("ALT: " + altVar);
titleVar = links_xml.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
trace("TITLE: " + titleVar);
trace("-------------------------------------");
}
} else {
trace("error loading xml");
}
};
Thanks! - tried it, doesn't work for me - i guess button code should also be changed...
there is NO button code here.. this is JUST to get your XML..and be able to trace/find EACH element/value in EACH menu item
I just tested it.. using the sample XML you supplied.. I found ALL values..
does flash MX have loadVar objects?? even?..that may be the problem? I cant remember.. oh wait..you said your loadVar object was working...right?..
And how do I insert that values on to button? ... I'm being boring... awww...
One last favour if I can ask - I'll use code that worked with button but only if you have any idea why it doesent work when link has http://ww... in it - as I posted few posts ago - if I can make that work that would be it...
Thank you one more time.
Yes code you gave me works it shows all data that is in xml nodes but I dont know to put it on buttons...
real quick before I leave for work:
example code:
Code:links_xml = new XML();
links_xml.load("menulink.xml");
links_xml.ignoreWhite = true;
links_xml.onLoad = function(success) {
if (success) {
trace("XML: " + links_xml);
totalLinks = links_xml.firstChild.childNodes.length;
trace("TOTAL LINKS: " + totalLinks+newline);
for (i = 0; i < totalLinks; i++) {
trace("LINK " + i + " DETAILS:");
_root.urlVar = links_xml.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
trace("URL: " + urlVar);
_root.altVar = links_xml.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
trace("ALT: " + altVar);
_root.titleVar = links_xml.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
trace("TITLE: " + titleVar);
trace("-------------------------------------");
}
} else {
trace("error loading xml");
}
};
example button code:
on(press){
getURL("http://www.yourdomain.com/folder/+"_root.urlVar);
}
is an example.. however all buttons will have the LAST url added.. dsince you are only using 1 var.. need to use _root["urlVar"+i]
basically since your in MX you can ASSIGN button actions..as your button dont have instance name (do they?) so you need to dump the value to a VARIABLE so the button can grab it in its execution..