How to implement Undo and Redo feature in as3

前端 未结 4 997
悲&欢浪女
悲&欢浪女 2021-01-27 14:33

I am going to create an application in that i have to implement an Undo and Redo feature. In the application there will be multiple objects located on stage and

4条回答
  •  [愿得一人]
    2021-01-27 15:32

    the simplest way I can think of is creating an action object, where you have the old state and the new state and the object that changed.

    every time an action that would get an undo feature is fired, fill out this data in the action object

    when you hit undo, revert to the before state of the object and push the action into the redo stack.

    This should be able to handle most common changes. Things like delete/undelete need a little extra tweaking. I would just put in all properties at the time of deletion, and use a create function when handling the undo.

    I would suggest using a string for parameters and value combinations for the before and after states, that way you can handle additional functions without changing the undo/redo functionality.

    This is more of a quick and dirty way, you can also do it using design patterns and proper OOP ways of dealing with this as others have mentioned.

提交回复
热议问题