如何在as3中实现撤消和重做功能
我将创建一个应用程序,我必须实现撤消和重做功能。 在应用程序中,舞台上将有多个对象,用户可以自定义 物体的位置。但是当用户单击“撤消”时,对象将恢复为默认值 位置,单击重做对象后将移动到新位置。
所以我的问题是如何在我的应用程序中应用这些功能? 有没有图书馆或第三方课程?
有人可以帮助我吗?
提前致谢。
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 user can customize
the position of the objects. But when user clicks on Undo the object go back to their default
position and after clicking on redo object will move on the new position.
So my question is how can i apply these feature in my application?
Is there any library or any third party classes?
Can some one help me?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看命令模式。它非常适合撤消/重做类型的问题。
Take a look at the command pattern. It's well suited to undo/redo type problems.
如果您只想要两种不同的状态(默认状态和“已更改”),那么实现起来应该非常简单。将每个对象的新值和更新值存储在数组中,并在按“撤消”或“重做”时设置相关数组的位置。
如果您需要更复杂的东西,您可以将您所做的一切存储为不可撤消的“操作”。例如,有一个类(例如“Action”)和多个子类(“Move”、“ChangeColor”等)。它们包含它们执行的更改(我们应该移动多少像素)以及执行操作(移动对象 X 像素)和撤消操作(移动对象 -X 像素)的方法。
If you only want two different states (default and "changed"), it should be pretty trivial to implement. Store the new values and the updated values for each object in arrays, and set the positions from the relevant array when you press "undo" or "redo".
If you need something more complicated, you could store everything you do as an "action" which is undoable. Eg, there is a class (for example "Action") with several child classes ("Move", "ChangeColor" etc). They contain the change they perform (how many pixels we should move) and methods for performing the action (move object X pixels) and undoing the action (move object -X pixels).
我能想到的最简单的方法是创建一个动作对象,其中有旧状态、新状态以及更改的对象。
每次触发将获得撤消功能的操作时,
请在单击撤消时在操作对象中填写此数据,恢复到对象之前的状态并将操作推入重做堆栈。
这应该能够处理最常见的更改。诸如删除/取消删除之类的事情需要一些额外的调整。我只是在删除时放入所有属性,并在处理撤消时使用创建函数。
我建议使用字符串作为参数以及之前和之后状态的值组合,这样您就可以在不更改撤消/重做功能的情况下处理其他功能。
这是一种快速而肮脏的方法,您也可以使用设计模式和正确的 OOP 方法来处理此问题,正如其他人提到的那样。
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.
这是我的自定义类,用于在舞台上撤消和重做多个对象。有不同的模式可用于撤消和重做操作,但对我来说,这是撤消和重做的简单方法。我已经在我的项目中完美且成功地实现了这一点。
要使用此类,只需导入该类
,
然后创建用于撤消和重做的单击事件:
对我来说,这很好用...希望这对其他人也有帮助...:)
This is my customize class afor undo and redo multiple objects on stage. There is different pattern which can be used for the undo and redo operation but for me this is the simple way for undo and redo. I have perfectly and successfully implement this in my project.
To Use this class only import the class
and after that
After that create click event for undo and redo:
For me this works fine... Hope this helps others too...:)