import com.flashloaded.ui.tree.TreeMemento;
const MAX_UNDOS:uint = 20;
var states:Array;
var stateIndex:int;
main();
function main():void {
states = [];
stateIndex = 0;
enableStateButtons();
}
function enableStateButtons():void {
undo_bn.enabled = stateIndex > 0;
redo_bn.enabled = stateIndex < states.length-1;
}
function addState():void {
states.push(tree.getMemento());
if (states.length > MAX_UNDOS) {
states = states.slice(-MAX_UNDOS);
}
stateIndex = states.length-1;
enableStateButtons();
}
undo_bn.addEventListener(MouseEvent.CLICK, onUndo);
function onUndo(event:Event):void {
tree.setMemento(states[--stateIndex] as TreeMemento);
enableStateButtons();
}
redo_bn.addEventListener(MouseEvent.CLICK, onRedo);
function onRedo(event:Event):void {
tree.setMemento(states[++stateIndex] as TreeMemento);
enableStateButtons();
}