dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Array of links to buttons

  1. #1
    perfectly perplexed
    Join Date
    Dec 2001
    Location
    blue planet.
    Posts
    130

    Array of links to buttons

    This has probably been asked a million times, but anyway, I'm trying to do an array of links that'll be inserted to each of the buttons.

    Here's what I did:

    I already have 5 buttons on the stage, labeled s1 - s5.

    Code:
    linkArray = new Array();
    linkArray = ["http://www.link1.html", "http://www.link2.html", "http://www.link3.html", "http://www.link4.html", "http://www.link5.html"];
    
    var amount = 5;
    for (i=1; i<=amount; i++) {
    	button = this["s"+i];
    	button.i = i;
    	button.onRelease = function() {		          getURL(linkArray[i],"_blank");
    	}
    }
    When I try to click on a button, the URL doesn't get passed at the onRelease instance, but a new window opens nonetheless.

    Am I missing something here? Please help. Thanks!

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Change this bit:

    getURL(linkArray[i],"_blank");


    to this:

    getURL(linkArray[this.i],"_blank");


    Otherwise, it doesn't know which i you are refering to when the function is called.

  3. #3
    perfectly perplexed
    Join Date
    Dec 2001
    Location
    blue planet.
    Posts
    130
    Hey,
    It works now. Thanks much!

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