A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: problem with button array

  1. #1
    Member
    Join Date
    Sep 2004
    Posts
    44

    problem with button array

    Hello Community ( You last visited: 05-10-2005 at 11:08 AM !)

    long time no see

    I'm loading some xml to populate urls for buttons


    Code:
    var home:MovieClip = this;
    
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("template.xml");
    
    function loadXML(loaded) {
        if (loaded) {
            xmlNode = this.firstChild;
    
            weburl = [];
            total = xmlNode.childNodes.length;
            for (i=0; i<total; i++) {
                weburl[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                
                var mc:MovieClip = home["_icon" + i];
                var url_txt:String = weburl[i];
                trace(url_txt);
                
    
                mc.onRollOver = function() {
                    //getURL(url_txt, "_BLANK");
                    trace(url_txt);
                }
            }
        } else {
            content = "file not loaded.";
        }
    }
    when I run this code i get back the list of urls, but when I rollover the button it only gives me back the last url for all the buttons.

    Can someone point me in the right direction? Any help is much appreciated.

    thanks for looking!

  2. #2
    flashmo.com
    Join Date
    Sep 2003
    Posts
    115
    Please take a look at below 2 flash source files. You will get an idea.

    Vertical Menu
    Horizontal Menu

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    When u press the button 'i' is simple the last value that the loop incrementer 'i' had .. assign an id to the movieclips before hand:

    Code:
    function loadXML(loaded) {
        if (loaded) {
            xmlNode = this.firstChild;
    
            weburl = [];
            total = xmlNode.childNodes.length;
            for (i=0; i<total; i++) {
                weburl[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                
                var mc:MovieClip = home["_icon" + i];
    	    mc.id = i;
              
                mc.onRollOver = function() {
                    //getURL(url_txt, "_BLANK");
                    trace(weburl[this.id]);
                }
            }
        } else {
            content = "file not loaded.";
        }
    }
    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