2/15/2010 2:54:31 AM
Title:
undo operation in flex application
I want to create a notepad,I want to do undo operation as that in notepad.how to get that.
HELP ME PLEASE
2/15/2010 3:06:56 AM
To create a Undo and Redo operation in flex application similar to notepad you have to create an array in which you can store a snapshot of current data. On pressing an Undo button you can restore the old data from previous position of array and on Redo you can move forward in the array until finished. By this method you can create any number of Undo / Redo operations.
2/15/2010 3:34:40 AM
Hi rani , see this code for Undo redo in flash like notepad.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="1024" minHeight="768">
<mx:Script>
<![CDATA[
private var dataArray:Array= new Array();
private var currentData:int;
private function saveData():void{
if(dataArray.length<10){
dataArray.push(txtArea.text);
}else{
dataArray.splice(0,1);
dataArray.push(txtArea.text);
}
currentData= dataArray.length-1;
}
private function undo():void{
if(currentData>0){
txtArea.text=dataArray[currentData-1]
currentData=currentData-1;
}
}
private function redo():void{
if(currentData<dataArray.length-1){
txtArea.text=dataArray[currentData+1]
currentData=currentData+1
}
}
]]>
</mx:Script>
<mx:TextArea id="txtArea" x="21" y="10" width="325" height="104" change="saveData()"/>
<mx:Button x="21" y="137" label="Undo" click="undo()"/>
<mx:Button x="231" y="137" label="Redo" click="redo()"/>
</mx:Application>