# Problem on button script (Statement must appear within on handler)

**URL:** https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702
**Category:** flash
**Created:** [October 22, 2003, 5:02pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702 "2003-10-22T17:02:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dcnyc](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@dcnyc](https://forum.kirupa.com/u/dcnyc)
#### Post date: [October 22, 2003, 5:02pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702/1 "2003-10-22T17:02:30Z")

</div>

This is what I get in the output window:  
Statement must appear within on handler back\_button.onRelease =function () {  
can anybody help on this? what is wrong?

---

<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: [October 22, 2003, 5:38pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702/2 "2003-10-22T17:38:53Z")

</div>

What statement do you get the error on?

If you don’t know, then post your code and I’m sure someone will figure it 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: [October 22, 2003, 5:40pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702/3 "2003-10-22T17:40:43Z")

</div>

The problem is that your statement is not within an on handler.

When putting code directly on a button you don’t use dynamic event handlers (which is what you have in your first post), you use static event handlers. Like this… [AS]on (release){  
//do this  
}[/AS] Dynamic event handlers are for dynamically assigning the events via actionscript (usually on a frame).

---

<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: [October 22, 2003, 5:52pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702/4 "2003-10-22T17:52:53Z")

</div>

thank you guys. can anybody check my file?

---

<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: [October 22, 2003, 6:54pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702/5 "2003-10-22T18:54:10Z")

</div>

The problem is exactly what I stated in my last post. You have actions on your button in the lower left corner, but you have them in a dynamic event handlers instead of a static event handler and that is why you are getting the error.

Also, you don’t need the onLoad handler on the frame, when the frame is hit those actions are called anyway so the onLoad doesn’t do anything.

---

<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: [October 22, 2003, 9:55pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702/6 "2003-10-22T21:55:58Z")

</div>

could you write exactly what I have to change on these buttons? Thank you

---

<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: [October 22, 2003, 10:02pm UTC](https://forum.kirupa.com/t/problem-on-button-script-statement-must-appear-within-on-handler/33702/7 "2003-10-22T22:02:09Z")

</div>

You can’t replace “back\_button.onRelease = function() {” with “on (release) {” by yourself :h:
