Functions and sub-functions

I think i’m a little confused about functions.

I have one function that puts text in a text field and makes a button goto a url onRelease.

The code is like this:

 item.onRelease = function() {
	myButton.onRelease = function() {
getURL("http://google.com", "_blank");
}
	talk = this.txt;
}

the only problem is that the button doesn’t work onRelease. i think that it is because there are too many functions there, but at the same time, i think it’s just me…

any advice?

thx in advance.

No, the code you have there is fine. The problem is most likely the path. Try this:


  item.onRelease = function() {
  trace(myButton);
      myButton.onRelease = function() {
  getURL("http://google.com", "_blank");
  }
      talk = this.txt;
  }
  

And let me know what that outputs. Remember that clicking on myButton will only function after having clicked on item.

yea… ok, that works, but only if the url in getURL isn’t a variable… btw, this is all from xml, but don’t worry, all the xml shtuff works fine… i’ve got this variable, item.go, which is an attribute in xml that holds the url…

here is the updated code:

item.onRelease = function() {
	trace(viewer);
	   viewer.onRelease = function() {
	   getURL("this.go", "_blank");
	 };
	   talk = this.txt;
	  this.viewer.onRelease;
			};

also, i tried getURL(“this.go”) w/o “”, and it doesn’t work.

…any more suggestions? Thanks for your help! :slight_smile:

Ah, but there you’ve got two errors. One, the quotes, and two, the this. The quotes shouldn’t be there because you’re using a string with quotes, and not the variable. So get rid of the quotes. Another thing is the this: since the code is placed inside the onRelease handler of viewer, this will target to viewer. Outside of the viewer onRelease but still inside the item onRelease, this will target to item. So to fix it, use this code:

item.onRelease = function() {
	theURL = this.go;
	viewer.onRelease = function() {
		getURL(theURL, "_blank");
	};
	talk = this.txt;
	this.viewer.onRelease;
};

By the way, that last line is useless. Don’t you mean viewer.onRelease(); ? That will immediately execute the onRelease handler, which I can imagine you wanted to add to debug faster.

Since you are also using XML I strongly advice that you make sure that you’re not using variables that haven’t loaded yet.

omg you are an actionscript GOD! thank you so very much… this has been driving me MAD all morning… THANK YOU!

peace out

You’re welcome :slight_smile: