PDA

View Full Version : Gah, fors, arrays, and getURLs



nathan99
November 4th, 2005, 09:41 PM
hey guys, wats wrong with this


pagelist = new Array();
pagelist[0] = home;
pagelist[1] = tutorials;
pagelist[2] = examples;
pagelist[3] = archives;
pagelist[4] = forum;
pagelist[5] = wip;
pagelist[6] = about;
link = new Array();
link[0] = "home";
link[1] = "tutorials";
link[2] = "examples";
link[3] = "archives";
link[4] = "forum";
link[5] = "wip";
link[6] = "about";
for (i=0; i<pagelist.length; i++) {
pagelist[i]._alpha = 50;
pagelist[i].onRelease = function() {
getURL(link[i]);
};
}


i want it to link to the reletive object in th "link" array. Once it works, ill shorten the code dw bout that.

TheCanadian
November 4th, 2005, 09:46 PM
Try this :):


pagelist = new Array("home", "tutorials", "examples", "archives", "forum", "wip", "about");
link = new Array("home", "tutorials", "examples", "archives", "forum", "wip", "about");
for (i = 0; i < pagelist.length; i++) {
_root[pagelist[i]]._alpha = 50;
_root[pagelist[i]].onRelease = function() {
getURL(link[i]);
};
}

nathan99
November 4th, 2005, 09:50 PM
lol thats exactly the same, except u have changed thepagelist array. Thus, the links still dont work.

lostinbeta
November 4th, 2005, 10:00 PM
You can't pass 'i' into the handler. So you need to dynamically create a variable in the clip with the value of 'i' and use that.

pagelist = new Array();
pagelist[0] = home;
pagelist[1] = tutorials;
pagelist[2] = examples;
pagelist[3] = archives;
pagelist[4] = forum;
pagelist[5] = wip;
pagelist[6] = about;
link = new Array();
link[0] = "home";
link[1] = "tutorials";
link[2] = "examples";
link[3] = "archives";
link[4] = "forum";
link[5] = "wip";
link[6] = "about";
for (i=0; i<pagelist.length; i++) {
pagelist[i]._alpha = 50;
pagelist[i].id = i;
pagelist[i].onRelease = function() {
getURL(link[this.id]);
};
}

And well, while we are at it ;)

pagelist = [home, tutorials, examples, archives, forum, wip, about];
link = ["home", "tutorials", "examples", "archives", "forum", "wip", "about"];
for (i=0; i<pagelist.length; i++) {
pagelist[i]._alpha = 50;
pagelist[i].id = i;
pagelist[i].onRelease = function() {
getURL(link[this.id]);
};
}

nathan99
November 4th, 2005, 10:35 PM
mm that didnt work :S

TheCanadian
November 4th, 2005, 11:16 PM
Probally 'cause your links aren't actually linking to anything (they are just strings):


pagelist = [home, tutorials, examples, archives, forum, wip, about];
link = new Array("home", "tutorials", "examples", "archives", "forum", "wip", "about");
for (i = 0; i < pagelist.length; i++) {
pagelist[i]._alpha = 50;
pagelist[i].id = i;
pagelist[i].onRelease = function() {
getURL("http://www." + link[this.id] + ".com");
};
}

nathan99
November 5th, 2005, 01:40 AM
lol dw i got it