Undo/Redo for all your TextFields

I made the TextField undo component. Add this component to any Flash or Flex application and all your text components will have undo and redo. This has been open sourced and is on http://code.google.com/p/undo-textfields/.

Instead of making different Flex and Flash components to use in place of the available components, I made one that adds undo to existing text components. It should work in Flash and in Flex, though I just have a Flex example to show you today. You can see that it can be container specific, though you would probably just put it on the root of your application or the stage. Type in the text components in the top panel. Then do the same in the bottom. You should be able to press Ctrl+Z and Ctrl+Y (or Ctrl+Shift+Z) to undo and redo. If you’re on a Mac just substitute Ctrl with Cmd. I’ve only tested it in Safari and Firefox on a Mac. I hope the key command work on other machines without issue. But I also added a couple of menu items to the right-click context menu. Give it a whirl below, view the source, and see how easy it is to add text undo and redo to all your existing applications without any refactoring.

Update: The keyboard shortcuts don’t work in the ActiveX version of Flash (Internet Explorer on Windows).

Let me know if the key-shortcuts don’t work on your system. Maybe phase 2 can be some javascript magic to capture those better.

56 Responses to “Undo/Redo for all your TextFields”

  1. Jacob Wright Says:

    I believe a more recent version of the player has an event dispatched when pasting text. You might look at that if you’re minimum player requirements is high enough.

  2. Stathis Says:

    Hello again. Thanks for the answer. I’ve just tried with the latest version of flash player and the result is still the same.

    I use flash player 10,1,85,3. To which version are you referring?

    Anyway, i found a workaround which seems to be working well until now. Inside file UndoTextField.as and in function onTextChange.

    else if (lastAction == ACTION_TYPE) {
    if(textField.caretIndex – lastSelection[0] > 1) {
    history.executeCommand(new CommandAlterText(textField, lastValue, lastSelection));
    } else {
    history.executeCommand(new CommandType(textField, lastValue, lastSelection));

  3. Stathis Says:

    By the way, i have added custom commands and events in order to create a code editing component (with syntax highlighting) as part of a simple IDE for a simple programming language used for educational purposes in greece.

    If anyone is interested for the code just mail me :
    sstergou ΑΤ gmail DΟΤ com

  4. Jacob Wright Says:

    I haven’t added support for right-click paste. I only suggested it might be able to be supported in a recent version of the player, but I’m unsure.

    If you’re sharing your code you should open source it and put it up on github or Google code. I’m sure a lot of people would be interested in at least looking through it and learning a thing or two, even if they don’t need a simple IDE.

  5. SINDHU VK Says:

    Undoredo not working in IE browsers though IE listens for keydown and key up events.

    public function creationCompleteApplication():void
    txtfield.addEventListener(KeyboardEvent.KEY_UP, keyHandlerfunction);

    private function keyHandlerfunction (evt:KeyboardEvent):void
    trace(“keyHandlerfunction: ” + evt.keyCode);
    //Alert.show(“———–> number ” + evt.keyCode);
    if(evt.ctrlKey && evt.keyCode == 90)

    Alert.show(“ctrl z pressed” + undoInstance.target);


    Thanks in advance

  6. Kal Says:


    Nice work! Thank you! Could you please post/enable code for the example above.
    Much appreciated!