1 Reply Latest reply on May 30, 2012 9:15 AM by graljackal

    Undo/Redo UndoManager




      I am new to Flex and I need to implement Undo/Redo features. Following the example shown at http://blog.onebyonedesign.com/actionscript/playing-around-with-the-new-undomanager/ I tried to do it myself, but obviously something is not right as it is not working. I am tired and I believe that what is wrong is so obvious that someone else will find it in 3 min.


      What I tried to to is really simple: a have a panel, with one text input control and two buttons. When I click on the 1st button, I wanted it to change whatever text I have written in the text input control for "Trying undo". When I click on Undo, I expected it to put the text original text. But neither of those two actions is happening. I don't see the change to "Trying undo" and I doesn't come back to the original text either.


      I post the code to see if someone can give a hint of what I am doing wrong.


      Thanks in advance


      Adobe Window where the controls are


      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">


                  import flashx.undo.UndoManager;
                  import undo.ChangeControlText;
                  private var undoManager:UndoManager = new UndoManager();
                  protected function btnChangeText_clickHandler(event:MouseEvent):void
                      var newText : String = "Trying undo";
                      var operation : ChangeControlText = new ChangeControlText(txtInputText.text, newText, txtInputText);                   


                  protected function btnUndo_clickHandler(event:MouseEvent):void


              <!-- Place non-visual elements (e.g., services, value objects) here -->
          <s:Panel x="132" y="38" width="321" height="249" title="Will undo work?">
              <s:Button x="31" y="160" label="Change" id="btnChangeText" click="btnChangeText_clickHandler(event)"/>
              <s:Button x="133" y="161" label="Undo" id="btnUndo" click="btnUndo_clickHandler(event)"/>
              <s:TextInput x="31" y="30" id="txtInputText" text="I'd like it to work" width="172"/>


      Action Script class wheremy undo/redo functions are defined.


      package undo
          import flashx.undo.IOperation;
          import spark.components.TextInput;


          public class ChangeControlText implements IOperation
              private var previousText: String;
              private var currentText : String;
              private var textControl : TextInput;
              public function ChangeControlText(previousText:String, currentText:String, textControl:TextInput)
                  this.previousText = previousText;
                  this.currentText = currentText;
                  textControl = textControl;
              public function performUndo():void {
                  textControl.text = previousText;
              public function performRedo():void {
                  textControl.text = currentText;