PDA

View Full Version : Reverse last action with button?


jiminy_macca
08-06-2008, 12:47 PM
Is it possible? Say I click a button that plays a section of a movieclip. Is it possible to reverse that action, or undo it somehow when another button (any other button) is clicked?

sixtyfootersdude
08-06-2008, 02:08 PM
This probably isnt the easiest way to do this but lets say you have 3 buttons and one undo button:

button one - calls function 1
button two - calls function 2
button three - calls function 3

function 1{
move an object 10 pix to the right
}

Depending on what your functions do you could create functions that do the oposite ie:

function 1 undo{
move the object 10 pix to the left
}

Whenever button 1,2 or 3 is pressed push an int of the press onto a stack. When the undo button is pressed pop the int off and call that function.

ie:

var stack:Array = new Array();

function1{
//all other stuff
stack.push(1);
}

functioUndo{
var toDo:int = stack.pop();
if(toDo==1)
function1undo();
if(toDo==2)
...
}

Good Luck