I have a simple text editor with cut, paste and undo buttons. I have this for cut and paste but i don't how to create undo button?
var clipboardFmt:TextFormat = new TextFormat();
var initialPoint:Number = new Number();
var finalpoint:Number = new Number();
var clipBoard:String = new String();
cut_button.addEventListener(MouseEvent.CLICK,cutText);
paste_button.addEventListener(MouseEvent.CLICK, pastefromClipboard);
function cutText(event:MouseEvent):void
{
clipBoard = txt.text.substring(txt.selectionBeginIndex,txt.selectionEndIndex);
System.setClipboard(clipBoard);
txt.replaceText(txt.selectionBeginIndex,txt.selectionEndIndex,"");
}
function pastefromClipboard(e:Event):void
{
txt.replaceText(txt.selectionBeginIndex,txt.selectionEndIndex,clipBoard);
finalpoint = initialPoint + clipBoard.length;
txt.setSelection(initialPoint,finalpoint);
txt.setTextFormat(clipboardFmt, initialPoint,finalpoint);
}
txt.addEventListener(Event.CHANGE,count);
function count(e:Event):void
{
wn.text = countWords(txt.text);
function countWords(input:String):int
{
return input.match(/[^\s]+/g).length;
}
}