PDA

View Full Version : getting URL from xml into for loop



Samurai
November 23rd, 2005, 05:52 PM
Hey people,

I'm having a small problem. I have an xml file with various attributes in them, and a flash file. The flash file is basically a list of buttons that is derived from a single movieclip that gets duplicated based on how many nodes are in the xml file. my problem is that when I click on the buttons they all go to the same url. How can I fix this? Come on people, there must be an actionscript guru out there who is looking for a challenge :)

Thanks for all the help I've recieved so far from Barn, I just need one more very small thing remedied.
here's my code (sorry if the as tag isn't working, i forget what it is again):

<as>

for (var i = 0; i<rows; i++) {
var thematrix = smile.duplicateMovieClip("smile"+i, i);
var images = thematrix.createEmptyMovieClip("image"+i, i);
var info = thematrix.createEmptyMovieClip("info", 10);
var button = thematrix.createEmptyMovieClip("the_button", 5);
info.createTextField("txt", 0, 15, -20, 100, 100);
picHolder = this.firstChild.childNodes[i];
info.txt.text = picHolder.attributes.title;
images.loadMovie(picHolder.attributes.thmb);
thematrix._x = xpos+(wclip+hspace)*(i%columns);
thematrix._y = ypos+(hclip+vspace)*Math.floor(i/columns);
thematrix.onRollOver=function(){
this.gotoAndPlay(2);
}
thematrix.onRollOut=function(){
//if(thematrix._currentframe==
this.gotoAndPlay(8);
}
//thematrix.onRelease=function(){
// getURL(picHolder.attributes.page , "_blank");
//}
//thematrix.onRelease = function(){
thematrix.onRelease = function(){
getURL(picHolder.attributes.page, "_blank");
//getURL(picHolder.attributes.page, "_blank");

}
}
}

<as>

THANKS TO ANYONE WHO CAN HELP ME OUT!

TheCanadian
November 23rd, 2005, 08:21 PM
When you reference a varible, it will take the last defined value of it. Thus each button will open the the last page attribute of your XML file. Try this:


thematrix.link = picHolder.attributes.page;
thematrix.onRelease = function() {
getURL(this.link, "_blank");
};


By the way, the AS tags are [ as] [ /as] (with no spaces).

Samurai
November 24th, 2005, 10:11 AM
Thanks a bunch THECANADIAN! That worked well. I've learned a ton about loops from this project I've had to do for work, and also from a few people here on the forum, this is why flash is growing so well, because people are willing to share information and help each other out! :) Thanks.

I'm Canadian also, hail from the scarborough/toronto area, leafs lost last night :( I am going to assume you're from calgary THECANADIAN. flames had a really crappy start, but they're (forgive the pun)...heating up! Crosby for mayor, ovechkin for janitor.