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..
is how you will map your button vars out.Code:links_xml = new 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);
/*
//loop through XML to check values..
for (i = 0; i < totalLinks; i++) {
trace("LINK " + i + " DETAILS:");
this[urlVar +i] = [links_xml.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue];
urlvar1 = links_xml.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
trace("URL: " + this[urlVar+i]);
_root[altVar+i] = links_xml.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
trace("ALT: " + _root[altVar+i]);
_root[titleVar+i] = links_xml.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
trace("TITLE: " + _root[titleVar+i]);
trace("-------------------------------------");
*/
//assign URL values to variables
urlVar1 = links_xml.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
trace("URL1 = " + urlVar1);
urlVar2 = links_xml.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;
trace("URL2 = " + urlVar2);
urlVar3 = links_xml.firstChild.childNodes[2].childNodes[0].firstChild.nodeValue;
trace("URL3 = " + urlVar3);
//assign alt text to variables
altVar1 = links_xml.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
trace("URL1 = " + altVar1);
altVar2 = links_xml.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
trace("URL2 = " + altVar2);
altVar3 = links_xml.firstChild.childNodes[2].childNodes[1].firstChild.nodeValue;
trace("URL3 = " + altVar3);
//assign title data to varables
titleVar1 = links_xml.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue;
trace("URL1 = " + titleVar1);
titleVar2 = links_xml.firstChild.childNodes[1].childNodes[2].firstChild.nodeValue;
trace("URL2 = " + titleVar2);
titleVar3 = links_xml.firstChild.childNodes[2].childNodes[2].firstChild.nodeValue;
trace("URL3 = " + titleVar3);
}else {
trace("error loading xml");
}
};
links_xml.load("menulink.xml");
(or you could create an object or array and dump the values to that I suppose too)
button:
Code:on (release) {
getURL("http://www.yourdomain.com/"+urlVar1);
getURL(urlVar1);
trace("URL1: "+urlVar1);
trace("URL2: "+urlVar2);
trace("URL3: "+urlVar3);
}
Thanks! - it works fine but I have same problem as with that code before - when I try to put link to another site in xml (http://www.somesite.com) and click on that button in flash nothing happens, links that are local work fine (page1.php etc..)...
code doesent like me...
you cant have it both ways.. either you want to append the http://www.yourdomain.com stuff to the value in the XML or not. up to you.
either check for it (to see if the value starts with http://www and do NOT append the prefix to the string.... or ALWAYS use absolute values in the xml)
Well thank you on all the help - big help!
do you know to check if the string (xml node value) starts with http:// (or whatever)?
and if NOT add it? (like the line of code used above)
getURL("http://www.yourdomain.com/"+urlVar1);
that means it will take whatever is in the urlVar xml node..and add http://www.yourdomain.com/ to the front of it.
I just noticed my previous post might sound sarcastic - its not... I really aprecciate your help and you have helped me a lot!
OK I managed to find what problem was... stupid... well I noticed that everything works when menu is in flash/test movie or in flash player but in IE it wasnt working so I opened it in FF and when I clicked pop up warned me I need to change settings for flash player so it can communicate with other sites (?!) ok so I did and now it works - IE gave no notice about that it just didnt do nothing...
I changed code a bit for buttons that will have http links (removed one line)
Question now is other ppl using IE with flash settings to "always ask" will have same problem as I did - when they click button nothing will happen, and IE wont tell them what problem is... dont see a way to solve this one...Code:on (release) {
getURL(urlVar4);
trace("URL1: "+urlVar1);
trace("URL2: "+urlVar2);
trace("URL3: "+urlVar3);
}
Thanks
are you testing this ON-LINE? like uploaded to a web host?..or are you just testing through IE>.by clicking on the HTML page from your desktop (so to speak?)
Yes I was testing html file from my comp not some on-line server...
Im fully understanding what your trying to explain..but it sounds like the FLASH Sandbox security issue.
When testing locally and (I think) your file has to make a call to the internet..it gives a warning.. (as to not be malicious).. you can follow link to Macro-Dobe's website and 'OK' that path (desktop...folder, directory) to be OK to call the playplayer/acces intenet...etc..etc.. without trouble..
once posted on line I do not think that is an issue anymore however.
Ok, great - thanks!
Hi,
:confused: I tried the code you have given.
Actually I have two buttons in two different flash files. I added the below given code, that you have given to load the xml file, to both the flash files.
To each button i added onpress function. I can access only the first link in the xml files on both cases.
What is the problem? I seem to be lost. :(
Shobha
Quote:
Originally Posted by whispers
no clue..how about you just try one..and get 1 to work..them move on..post you code...
this is a simple 1 frame .swf to show/load the XML..no multiple frames.. no double .swf...etc..
its a simple load the XML.. thats all this is.. loading the XML what you DO with the data is up to you.
What if the code is an array (arrays are new to me)? I am trying to call the links to buttons, but when I click the buttons, it says it is undefined.
XML is like this:Code:var root = this.firstChild;
for (var i = root.firstChild; i != null; i=i.nextSibling) {
aCaption.push(i.attributes.caption);
aLink.push(i.attributes.link);
}
populate();
}
};
importXML.load("gallery2.xml");
var aCaption = new Array();
var aLink = new Array();
function populate() {
for (i=0; i<aCaption.length; i++) {
this["box"+(i+1)+"_txt"].htmlText = aCaption[i];
this["link"+(i+1)+"_btn"].onRelease = function(){
getURL(aLink[i], "_blank");
}
}
}
Thank you! Oh, and it is Flash CS3 if that makes a difference.Code:<option caption="Blue 1" link="http://www.google.com"/>
Hi All,
I know I am responding to a very old post but I would be grateful if someone can send me this or similar file to this one. Actually I have to work on a similar thing the only difference is that I have to deal with Setups and Installation buttons.
my email id is [email protected].
Thanks in Advance !!
Faizan
huh?