A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35

Thread: How to control a buttons link using xml

  1. #21
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    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");
    is how you will map your button vars out.

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

  2. #22
    Junior Member
    Join Date
    Apr 2007
    Posts
    11
    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...

  3. #23
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    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)

  4. #24
    Junior Member
    Join Date
    Apr 2007
    Posts
    11
    Well thank you on all the help - big help!

  5. #25
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    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.

  6. #26
    Junior Member
    Join Date
    Apr 2007
    Posts
    11
    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)
    Code:
    on (release) {
    	getURL(urlVar4);
    	trace("URL1: "+urlVar1);
    	trace("URL2: "+urlVar2);
    	trace("URL3: "+urlVar3);
    }
    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...

    Thanks

  7. #27
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    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?)

  8. #28
    Junior Member
    Join Date
    Apr 2007
    Posts
    11
    Yes I was testing html file from my comp not some on-line server...

  9. #29
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    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.

  10. #30
    Junior Member
    Join Date
    Apr 2007
    Posts
    11
    Ok, great - thanks!

  11. #31
    Junior Member
    Join Date
    Jul 2008
    Posts
    1

    Unhappy I need help!!

    Hi,

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


    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");
    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"); 
    		link1 = myXML.firstChild.childNodes[0].firstChild.nodeValue;
    		link2 = myXML.firstChild.childNodes[1].firstChild.nodeValue; 
    	}    
    };       
    // call the actual XML file (step3) 
    myXML.load("whateverFile.xml");

  12. #32
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    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.

  13. #33
    Junior Member
    Join Date
    Jul 2008
    Posts
    7
    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.

    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");
    		}
    	}
    }
    XML is like this:
    Code:
    <option caption="Blue 1" link="http://www.google.com"/>
    Thank you! Oh, and it is Flash CS3 if that makes a difference.
    Last edited by 4LeggedHobey; 07-15-2008 at 10:03 AM.

  14. #34
    Junior Member
    Join Date
    Jun 2006
    Posts
    2

    Smile I know its an old post..if some can send me a similar file

    Quote Originally Posted by madzigian View Post
    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....
    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 faizan.indore@gmail.com.

    Thanks in Advance !!
    Faizan

  15. #35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center