View Full Version : Undo/Redo - text input
ckyidr9
07-19-2007, 12:19 AM
I was a little bit disappointed when I realized there was no built in (none that I know of) undo/redo for text input in AS3.
I've been trying to make a simple, reliable undo function myself but I'm not making great progress.
Has anyone any idea how to implement an undo function, or point me in the direction of some code that already exists?
dr_zeus
07-19-2007, 05:13 PM
I made an undo manager a while back. It's not my code, though, so I can only give you the concept.
Basically, every time the user does an undoable action, you add it to a stack (an Array will work). When they want to undo it, you take that action (it can be a custom object that stores certain parameters like the state before and/or after the action happened) and move it to a redo stack. The manager should dispatch an event so that you can reset the state of the application. Additional undos will continue to add to the top of this stack.
When you redo an action, actions are taken off the top of the redo stack and moved back to the top of the undo stack. Again, an event should be dispatched so that you can change the application state for the redone action.
Finally, remember that when something is on the redo stack, and the user initiates a new action, the redo stack should be cleared.
jsebrech
07-20-2007, 10:00 AM
What Dr. Zeus said. It's known as the "command pattern", see google or wikipedia for more info and examples. It's easy to implement, and if you design it right, you can implement an action history viewer/navigator (like in photoshop) on top of it almost effortlessly.
http://en.wikipedia.org/wiki/Command_pattern
ckyidr9
07-30-2007, 12:21 AM
Right so I went and wrote myself an undo/redo system for text input. I added "Undo" and "Redo" items to the context menu, funny how the word "Undo" is on the list of words no allowed in a custom ContextMenuItem, even though it is not used at all by the Flash player. Anyway, here is the code. Just paste it into the first frame of your movie and drag a Textarea component into the library.
So, here is that code ? (it says : "here is the code")... :-(
I really need this undo redo code for a textbox.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.