# Why doesn't this simple function work?

**URL:** <https://forum.kirupa.com/t/why-doesnt-this-simple-function-work/183795>\
**Category:** flash\
**Created:** [March 30, 2006, 3:23am UTC](https://forum.kirupa.com/t/why-doesnt-this-simple-function-work/183795 "2006-03-30T03:23:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_Hed](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rob\_Hed](https://forum.kirupa.com/u/Rob_Hed)\
**Post date:** [March 30, 2006, 3:23am UTC](https://forum.kirupa.com/t/why-doesnt-this-simple-function-work/183795/1 "2006-03-30T03:23:40Z")

</div>

Check out this simple attachment. You got your as  
my\_btn.onRelease = function() {  
trace(“It worked”);  
}

The Instance Name on the button is my\_btn. Ok, why does it work if the as is on the same frame as the button but not if you move the button over a frame. I thought the point of using a function was that you only need to write it once. I don’t want to put this function on every frame where the button is located.

What am I missing here?

---

<div class="post-metadata">

**Author:** ![B\_L\_U\_E](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@B\_L\_U\_E](https://forum.kirupa.com/u/B_L_U_E)\
**Post date:** [March 30, 2006, 3:31am UTC](https://forum.kirupa.com/t/why-doesnt-this-simple-function-work/183795/2 "2006-03-30T03:31:22Z")

</div>

The object needs to be loaded before you cana ssign a function to it like that. Simple as that. 🙂

---

<div class="post-metadata">

**Author:** ![RichL](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@RichL](https://forum.kirupa.com/u/RichL)\
**Post date:** [March 30, 2006, 10:16am UTC](https://forum.kirupa.com/t/why-doesnt-this-simple-function-work/183795/3 "2006-03-30T10:16:31Z")

</div>

You could have done it like this…

---

<div class="post-metadata">

**Author:** ![Rob\_Hed](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rob\_Hed](https://forum.kirupa.com/u/Rob_Hed)\
**Post date:** [March 30, 2006, 2:44pm UTC](https://forum.kirupa.com/t/why-doesnt-this-simple-function-work/183795/4 "2006-03-30T14:44:10Z")

</div>

> [@BlueNar](#):
>
> The object needs to be loaded before you cana ssign a function to it like that. Simple as that. 🙂

Ok. That makes sense. So as long as the action script comes anywhere on the timeline overlapping the instance name you are good.

In that sense it is a little different than other functions.  
thanks…
