# Functions and sub-functions

**URL:** <https://forum.kirupa.com/t/functions-and-sub-functions/113392>\
**Category:** Uncategorized\
**Created:** [June 17, 2004, 2:05pm UTC](https://forum.kirupa.com/t/functions-and-sub-functions/113392 "2004-06-17T14:05:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodyvisual](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bodyvisual/32/564_2.png) [@bodyvisual](https://forum.kirupa.com/u/bodyvisual)\
**Post date:** [June 17, 2004, 2:05pm UTC](https://forum.kirupa.com/t/functions-and-sub-functions/113392/1 "2004-06-17T14:05:38Z")

</div>

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:

```auto
 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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 2:08pm UTC](https://forum.kirupa.com/t/functions-and-sub-functions/113392/2 "2004-06-17T14:08:14Z")

</div>

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

```auto

  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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 3:29pm UTC](https://forum.kirupa.com/t/functions-and-sub-functions/113392/3 "2004-06-17T15:29:03Z")

</div>

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:

```auto
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! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 5:11pm UTC](https://forum.kirupa.com/t/functions-and-sub-functions/113392/4 "2004-06-17T17:11:21Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 5:21pm UTC](https://forum.kirupa.com/t/functions-and-sub-functions/113392/5 "2004-06-17T17:21:45Z")

</div>

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

peace out

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 5:35pm UTC](https://forum.kirupa.com/t/functions-and-sub-functions/113392/6 "2004-06-17T17:35:50Z")

</div>

You’re welcome 🙂
