A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: buttons from XML

  1. #1
    Junior Member
    Join Date
    Apr 2005
    Posts
    20

    buttons from XML

    hello!

    just need a quick answer to this... I've got buttons in my movie which are used for hyperlinks etc... however, I don't want to specify a URL in the actual movie, I want this data pulled from an XML file.

    The xml file (for example - link.xml) will read:

    <link>"http://www.mylink.com"</link>

    and I need the button to pull this link from the <link> field in link.xml. is this possible? if so... would someone be able to tell me what the actionscript would be?!

    many thanks!

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    The script will depend how you set up your movie, as long as all you want to do is pull in the links and not set any text labels on the buttons dynamically, should not be a problem.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Junior Member
    Join Date
    Apr 2005
    Posts
    20
    yeah, no text labels to be set dynamically.... just the link... is there some really easy actionscript fix for this?

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    how many buttons and what are their instance names, and how many links in the XML?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Junior Member
    Join Date
    Apr 2005
    Posts
    20
    4 buttons...

    btn_artlink - reading from <artist>
    btn_vvlink - reading from <vvlink>
    btn_buylink - reading from <buylink>

    and last but not least

    btn_staflink - reading from <staflink>

    all tags are in links.xml

  6. #6
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    ok assuming the xml looks like this:
    <links>
    <artist>http://www.somesite.com/somepage.htm</artist>
    <vvlink>http://www.somesite.com/somepage.htm</vvlink>
    <buylink>http://www.somesite.com/somepage.htm</buylink>
    <staflink>http://www.somesite.com/somepage.htm</staflink>
    </links>

    ActionScript:
    var linksXML:XML = new XML();
    //the order of this array is important. the first button listed will get the link listed first in the XML and so on for each button
    var linkBtns:Array = new Array(btn_artlink, btn_vvlink, btn_buylink, btn_staflink);
    linksXML.ignoreWhite = true;
    linksXML.onLoad = function (dat){
    if (dat){
    for(x=0; x< linkBtns.length; x++){
    linkBtns[x].lnk = this.firstChild.childNodes[x].childNodes[0];
    linkBtns[x].onRelease = function (){
    getURL(this.lnk);
    }
    }
    }else{
    trace ("XML failed to load");
    }
    }
    linksXML.load("links.xml");


    is the basic idea
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  7. #7
    Junior Member
    Join Date
    Apr 2005
    Posts
    20
    aww i cant get that to work!

  8. #8
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    is the fla small enough to post?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


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