Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically set target URLs on Movie Buttons

Status
Not open for further replies.

cmmps

Programmer
Aug 16, 2001
2
US
Hi all!
I'm trying to set dynamically target URLs on some movie buttons already created in design mode.
The URLs are defined in a XML file that is successfully loaded and parsed into variables. The problem resides on affecting the movie clip in order to link to a desired URL.

I've already tried to make this:

boxIdx = 0;
while (boxCurrentNode!=null) {
boxSubNodes = boxCurrentNode.firstChild;
eval("btnOrg_" + boxIdx).txtButton.text = boxSubNodes.firstChild.nodeValue;
boxSubNodes = boxSubNodes.nextSibling;
eval("btnOrg_" + boxIdx).onPress = function () { this.getURL(boxSubNodes.firstChild.nodeValue, '_self' } ;
boxIdx++;
boxCurrentNode = boxCurrentNode.nextSibling;
}

The text boxes are filled correctly but all the "onPress" events points to the URL of the last string on the XML file. It seems that the function created for each movie button is overwrited on all previous movie buttons...

Ideas?

Carlos - a LINUX addict! :)
 
One way around this would be to attach each URL as an id to the clip then call that from the function.

Code:
boxIdx = 0;
while (boxCurrentNode != null) {
	boxSubNodes = boxCurrentNode.firstChild;
	this["btnOrg_"+boxIdx].txtButton.text = boxSubNodes.firstChild.nodeValue;
	boxSubNodes = boxSubNodes.nextSibling;
	this["btnOrg_"+boxIdx].urlTarget = boxSubNodes.firstChild.nodeValue;
	this["btnOrg_"+boxIdx].onPress = function() {
		this.getURL(this.urlTarget, '_self');
	};
	boxIdx++;
	boxCurrentNode = boxCurrentNode.nextSibling;
}
 
Thanks a lot Wangbar! Is working fine!
However, the "this" clause didn't work and I had to use the "eval" clause instead.

Now the code looks like:
Code:
			boxIdx = 0;
			while (boxCurrentNode!=null) {
				boxSubNodes = boxCurrentNode.firstChild;
				eval("btnOrg_" + boxIdx).txtButton.text = boxSubNodes.firstChild.nodeValue;
				boxSubNodes = boxSubNodes.nextSibling;
				eval("btnOrg_" + boxIdx).urlTarget = boxSubNodes.firstChild.nodeValue;
				eval("btnOrg_" + boxIdx).onPress = function () {
					this.getURL(this.urlTarget, '_self');
				};
				boxIdx++;
				boxCurrentNode = boxCurrentNode.nextSibling;
			}

Regards,

Carlos - a LINUX addict! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top