Undo in TextFields

I presented on creating your own undo/redo at 360 MAX unconference and a uFlash meeting. People seemed interested in knowing how to do it, but were more interested in having the code. It really should be part of Flex TextAreas and TextInputs. So I was going to code up a couple custom components that extended TextArea and TextInput (e.g. UndoableTextArea) and release them for use. However, as Tyler reminded me, that wouldn’t work in Flash apps, only Flex. So I have a proposal and would like to get your feedback.

If I created a component that you put on the root of your application (or any MXML component) which added undo/redo to any/all INPUT TextFields with in Flash or Flex would that be better? If you’re not doing any custom INPUT TextFields I don’t see any issues. But it could cause problems if you’re doing your own text components. Also, I would do it by listening to Event.ADDED events and whenever a TextField is added to the display list it would initialize it and add some right-click menu items to it. And I can even make sure when I have script access through ExternalInterface to capture the Ctrl+Z key combo.

Comment and let me know if this would be better than the Flex components. It would work in Flash apps too is the nice part and also you could add it to existing applications without any find-replace. The downsides is it could interfere with text manipulation code you may have in place for custom text components. I’ll decide this week and get to work on it next!

4 Responses to “Undo in TextFields”

  1. iBrent Says:

    Hi Jacob!

    I saw your blog post on the Adobe news feed. I’m jealous ;). Great presentation at the uFlash meeting last year.

    My vote would be to see a component that can be used in Flash and Flex. I think more people could benefit if it were as simple to use as possible. Besides if someone has custom text manipulation code in their project, then they might know how to do what your offering anyway. But I think the majority of folks would benefit from this awesome component.


  2. Mark Says:


    Would it be more beneficial to create it as a static class so we can have the option to add the functionality to the textfields we want.

    So something like:
    TextFieldHistory.addItem( myTextField );

    Or just provide us with the event handler as a function rather than controlling all of our textfields? That way we can still have control over those textfields with custom text manipulation on.

    It’s just a thought, what does everyone else think?

  3. Roland Zwaga Says:

    I’m not sure if this scenario will be a wide-spread one. I would figure that I’d only want the undo capabilities on the textfields of my choosing, I’d prefer tighter control.

    By the way, just recently I released an early version of a small Flex undo library on googlecode:
    This library focuses more on undo history on arbitrary objects, not specifically textfields.

    I’d be interested in seeing your code to check out the appoach you’re using.



  4. Jana Says:


    My vote would be a simple component I could use in flex. So instead of putting in an mx:TextArea I would just use :AdvancedTextArea type of syntax. Simple is what is important to me.

    Wish you had one available to use right now!