Second press

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)

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]

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?

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.