A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Dynamically adding URLs to buttons

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    1

    Dynamically adding URLs to buttons

    I have an XML file that has a large group of buttons. (ex below)
    code:
    <unitedstates>
    <state name="WA">
    <enabled>1</enabled>
    <bordercolor>3F3F3F</bordercolor>
    <color>336699</color>
    <url>http://www.hotmail.com</url>
    </state>
    <state name="OR">
    <enabled>1</enabled>
    <bordercolor>3F3F3F</bordercolor>
    <color>336699</color>
    <url>http://www.gmail.com</url>
    </state>
    </unitedstates>


    I want to be able to dynamically have each of those buttons go to the URL I specified in the <url></url> tag.

    This is the code that I am trying to do as I loop through the XML file, but it's assigning it onrelease. I want to assign it at the beginning.

    code:

    for(var i = 0; i < xmlDoc_xml.firstChild.childNodes.length; i++){
    var strURL = xmlDoc_xml.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue;
    eval(stateName).onRelease = function(){
    trace(strURL);
    getURL(strURL, "_self");
    }
    }



    the problem with this is that it assigns the last URL in the XML file to the every button I click on. So in this instance, the WA button AND the OR button will both go to gmail.com because that's the last one it was assigned to.

    How do I add the right URL to the right button in that loop and have it stick?

    Thanks.

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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