# Second press

**URL:** <https://forum.kirupa.com/t/second-press/28564>\
**Category:** Uncategorized\
**Created:** [August 15, 2003, 1:14am UTC](https://forum.kirupa.com/t/second-press/28564 "2003-08-15T01:14:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo\_Geo](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Neo\_Geo](https://forum.kirupa.com/u/Neo_Geo)\
**Post date:** [August 15, 2003, 1:14am UTC](https://forum.kirupa.com/t/second-press/28564/1 "2003-08-15T01:14:16Z")

</div>

i used this AS to move a ball initially at (100,100) to (100,200). But how to make it goes back to (100,100) on my second press.

[AS]  
var endX = ball.\_x;  
var endY = ball.\_y;  
var speed = 3;  
function moveTo(x, y) {  
endX = x;  
endY = y;  
}  
ball.onEnterFrame = function() {  
this.\_x += (endX-this.\_x)/speed;  
this.\_y += (endY-this.\_y)/speed;  
};  
ball.onPress = function() {  
moveTo(100, 200);  
};  
[/AS]

(i got the AS somewhere here, in kirupaforum)

---

<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:** [August 15, 2003, 1:19am UTC](https://forum.kirupa.com/t/second-press/28564/2 "2003-08-15T01:19:38Z")

</div>

You will need to create a variable to hold a true of false value then use that to check if the button has been pressed.

[AS]var endX = ball.\_x;  
var endY = ball.\_y;  
var speed = 3;  
function moveTo(x, y) {  
endX = x;  
endY = y;  
}  
//create variable “triggered” in the ball object  
//set that value to false by default  
ball.triggered = false;  
ball.onEnterFrame = function() {  
this.\_x += (endX-this.\_x)/speed;  
this.\_y += (endY-this.\_y)/speed;  
};  
ball.onPress = function() {  
//if triggered variable in this objects value is false  
if (!this.triggered){  
//moveTo 100, 200  
moveTo(100, 200);  
//set triggered variable value to true (to say it has been pressed once)  
this.triggered = true;  
//else  
} else {  
//move the clip back to 100, 100  
moveTo(100, 100)  
//reset the triggered variable back to false  
this.triggered = false;  
}  
};[/AS]

---

<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:** [August 15, 2003, 1:26am UTC](https://forum.kirupa.com/t/second-press/28564/3 "2003-08-15T01:26:35Z")

</div>

great.  
but i don’t understand the ‘triggered’ false and true part. is there any tutorial or explanation about this in kirupa or any flash-help site?

---

<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:** [August 15, 2003, 2:44am UTC](https://forum.kirupa.com/t/second-press/28564/4 "2003-08-15T02:44:58Z")

</div>

triggered is just a variable that you assign the value of true or false to.

You start it out as false, then in the on press you use an if statement to check if the value is false, if it is then do the first thing you want it to do and then set the value of the variable to true, this acts as a switch so that when you press the clip again the value of the variable is no longer true so it goes to the else statement and runs what you want it to do second.
