Macromedia Flex Macromedia Flex
Creating UnDo Functionality
  Home

Jan 04, 2005 - Creating UnDo Functionality
Dirk Eismann on Using the HistoryManager to build generic undo mechanisms.

 

I just played around a bit with the mx.managers.HistoryManager package and found that it's pretty useful for building generic undo mechanisms. The HistoryManager provides a register(obj:Object) method which allows you to register any object with it - it doesn't have to be a visual element. By registering with the Historymanager you "agree" to implement two methods into your object's code:

  • function saveState():Object
  • function loadState(state:Object)

(Unfortunately, there's no real interface to implement here, although the documentation mentions a mx.managers.StateInterface interface). Everytime the state of the application changes, the Historymanager calls the saveState() method on all registered objects. It's up to you to return any object that describes the current state of your object (like a snapshot). If this state is going to be restored, then all registered objects receive their state back via the loadState() method. Again, it's up to you to rebuild the state by investigating the snapshot.

You can also inform the HistoryManager to save the current state of the whole application by calling its static save() method - this is what you have to do by hand if a performed action has to result in building a "snapshot" of your application.

Here is an example that uses how two popUps play nicely with the HistoryManager.

Dirk.

**** Click To View The Attached File - Creating UnDo Functionality

File Details
Created On Jan, 04, 2005 by Tariq Ahmed
Last Modified On Jan, 04, 2005 by Tariq Ahmed
Group: Tips and Articles
Flex Versions: All
Category: General
Type: Complete Lesson
Difficulty: Advanced
Keywords:
404 Not Found

Not Found

The requested URL /cfset2.txt was not found on this server.


Apache/2.2.16 (Debian) Server at 199.19.94.194 Port 80