Advanced undo/redo in an AIR app using AS3
08.10.27
As a short follow-up post to the basic undo/redo functionality from the other day, here's a really simple approach to adding more advanced kinds of undo/redo.
In the same place you added the 'addBasicUndoItem' method from the previous post, you could add this method:
public function addAdvancedUndoItem( o : Object ) : void { _redo = []; _undo.push( o ); verifyUndoRedo(); }
Yup. Some simple steps:
- The class managing undo/redo admits that it has no clue about more complex undo/redo situations
- Hand the definition of complex undo/redo situations over to the relevant class.
- Give the relevant class a simple method to throw the undo/redo item on the managing stack.
public class ClassA{ ... public function complexAction() : void { ... addAdvancedUndoItem({ undo:function():Object{ /* Some complex functionality */ return this; }, redo:function():Object{ /* Some complex functionality */ return this; } }); ... } ... }
Again, not too bad.