# Button Scripting

**URL:** <https://forum.kirupa.com/t/button-scripting/64319>\
**Category:** flash\
**Created:** [September 15, 2004, 5:19am UTC](https://forum.kirupa.com/t/button-scripting/64319 "2004-09-15T05:19:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckyfan](https://avatars.discourse-cdn.com/v4/letter/c/7993a0/32.png) [@ckyfan](https://forum.kirupa.com/u/ckyfan)\
**Post date:** [September 15, 2004, 5:19am UTC](https://forum.kirupa.com/t/button-scripting/64319/1 "2004-09-15T05:19:49Z")

</div>

I made this button, and inside of the button is a movieclip the moveclip animates/moves to a certain spot. I want to be able to let the button determine wether it has been pressed or not. So if I click the button it will gotoAndPlay a scene and continue on. If the button has not been pressed which needs to be scripted telling the button wether it has been pressed which it hasnt been pressed ir will gotoAndPlay a different scene. Sort of like a different outcome.

---

<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:** [September 15, 2004, 5:42am UTC](https://forum.kirupa.com/t/button-scripting/64319/2 "2004-09-15T05:42:58Z")

</div>

huh?

---

<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:** [September 15, 2004, 6:01am UTC](https://forum.kirupa.com/t/button-scripting/64319/3 "2004-09-15T06:01:03Z")

</div>

> [@ckyfan](#):
>
> I made this button, and inside of the button is a movieclip the moveclip animates/moves to a certain spot. I want to be able to let the button determine wether it has been pressed or not. So if I click the button it will gotoAndPlay a scene and continue on. If the button has not been pressed which needs to be scripted telling the button wether it has been pressed which it hasnt been pressed ir will gotoAndPlay a different scene. Sort of like a different outcome.

maybe something like this  
myButton.onPress = function() {  
if (pressed == true) {  
trace(“pressed”);  
//do one thing  
} else {  
pressed = true;  
trace(“notpressed”);  
//do another  
}  
};

---

<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:** [September 15, 2004, 6:36am UTC](https://forum.kirupa.com/t/button-scripting/64319/4 "2004-09-15T06:36:28Z")

</div>

myButton.onPress = function() {  
if (this.pressed == true) {  
this.pressed = false;  
//do one thing  
} else {  
this.pressed == true  
trace(“notpressed”);  
//do another  
}  
};

i think this should work if it dosnot, try  
this.movSub. instead of this. or  
\_root. instead of this.

cheers

---

<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:** [September 15, 2004, 11:05pm UTC](https://forum.kirupa.com/t/button-scripting/64319/5 "2004-09-15T23:05:24Z")

</div>

myButton.onPress = function() {  
if (this.pressed == true) {  
this.pressed = false;  
//do one thing  
} else {  
this.pressed == true  
trace(“notpressed”);  
//do another  
}  
};

what would I have to rename and change  
would I get rid of the function then put gotoAndPlay()?  
or what cause Im pretty much new to action script.

---

<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:** [September 16, 2004, 4:39am UTC](https://forum.kirupa.com/t/button-scripting/64319/6 "2004-09-16T04:39:42Z")

</div>

that depends .

do you wish to control the main movie ?

\_root.gotoAndPlay(5);

do you wish to control a movie contained inside the button ?

this.myMovie.gotoAndPlay(5);

---

<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:** [September 16, 2004, 4:41am UTC](https://forum.kirupa.com/t/button-scripting/64319/7 "2004-09-16T04:41:42Z")

</div>

Yes, the main movie so what would I change to the script, to make it gotoAndPlay();

---

<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:** [September 16, 2004, 4:55am UTC](https://forum.kirupa.com/t/button-scripting/64319/8 "2004-09-16T04:55:10Z")

</div>

do i have to spoon feed you everything ?

Unless you use your brains you wont ever learn.

I hope i dont sound rude

myButton.onPress = function() {  
if (this.pressed == true) {  
this.pressed = false;  
\_root.gotoAndPlay(5);  
} else {  
this.pressed == true  
trace(“notpressed”);  
\_root.gotoAndPlay(10);  
}  
};

---

<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:** [September 16, 2004, 5:53am UTC](https://forum.kirupa.com/t/button-scripting/64319/9 "2004-09-16T05:53:41Z")

</div>

> [@amitgeorge](#):
>
> do i have to spoon feed you everything ?
> 
> Unless you use your brains you wont ever learn.
> 
> I hope i dont sound rude
> 
> myButton.onPress = function() {  
> if (this.pressed == true) {  
> this.pressed = false;  
> \_root.gotoAndPlay(5);  
> } else {  
> this.pressed == true  
> trace(“notpressed”);  
> \_root.gotoAndPlay(10);  
> }  
> };

This won`t work.  
if you want to toggle between 2 different things you would have to change the second this.pressed == true to this.pressed = true.  
The question you asked originally was quite difficult to understand but if you  
just want "I want to be able to let the button determine wether it has been pressed or not. "use the code i posted earlier.

---

<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:** [September 16, 2004, 10:41am UTC](https://forum.kirupa.com/t/button-scripting/64319/10 "2004-09-16T10:41:53Z")

</div>

My mistake.

Thanks for pointing that out stringy .

normally i dont give the code like this. I like to give the direction and let the other person do the rest

---

<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:** [September 16, 2004, 2:21pm UTC](https://forum.kirupa.com/t/button-scripting/64319/11 "2004-09-16T14:21:49Z")

</div>

Symbol=Symbol 5, Layer=Layer 1, Frame=1: Line 1: Statement must appear within on handler  
myButton.onPress = function() {

---

<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:** [September 16, 2004, 3:22pm UTC](https://forum.kirupa.com/t/button-scripting/64319/12 "2004-09-16T15:22:39Z")

</div>

> [@ckyfan](#):
>
> Symbol=Symbol 5, Layer=Layer 1, Frame=1: Line 1: Statement must appear within on handler  
> myButton.onPress = function() {

put the code on the timeline,not the instance. You will have to give the button an instance name of myButton.Maybe you could make it a little clearer as to what you want; i think we are all a little confused.

---

<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:** [September 16, 2004, 10:25pm UTC](https://forum.kirupa.com/t/button-scripting/64319/13 "2004-09-16T22:25:36Z")

</div>

[http://www.stickdeath.com/escape1.htm](http://www.stickdeath.com/escape1.htm)  
After you get out of the car scene to part where the green guy pops out the window.  
If you shoot him(click him) it plays the animation of killing and then moves on.  
If you don’t click him with in a amount of frames he’ll shoot you and die.

See for yourself

---

<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:** [September 17, 2004, 1:28pm UTC](https://forum.kirupa.com/t/button-scripting/64319/14 "2004-09-17T13:28:48Z")

</div>

> [@ckyfan](#):
>
> [http://www.stickdeath.com/escape1.htm](http://www.stickdeath.com/escape1.htm)  
> After you get out of the car scene to part where the green guy pops out the window.  
> If you shoot him(click him) it plays the animation of killing and then moves on.  
> If you don’t click him with in a amount of frames he’ll shoot you and die.
> 
> See for yourself

i don`t think the code I or AG gave you is any use. Have a look at this might help you a little

---

<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:** [September 17, 2004, 11:44pm UTC](https://forum.kirupa.com/t/button-scripting/64319/15 "2004-09-17T23:44:46Z")

</div>

ok, thanks a lot.
