2013-08-09 2 views
0

잘라 내기, 붙여 넣기 및 실행 취소 버튼이있는 간단한 텍스트 편집기가 있습니다. 잘라 내기 및 붙여 넣기가 있지만 실행 취소 단추를 만드는 방법은 없습니까?AS3의 텍스트 입력란에 UNDO를 추가하는 방법은 무엇입니까?

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; 
    } 
} 

답변

0

변수에 텍스트 필드 텍스트 복사본을 저장해야합니다. 텍스트 필드의 값이 변경 될 때마다 변경 사항이 적용되기 전에 (이벤트는 TextEvent.TEXT_INPUT이라고 함) 텍스트 필드 값의 사본을이 변수에 저장하십시오. undo 버튼을 누르면 텍스트 필드 값을이 변수에 저장된 값으로 설정합니다.

이것은 한 단계 뒤로 되돌릴 수있는 가장 간단한 솔루션입니다. 단일 변수 대신 배열을 사용하여 몇 단계를 되돌릴 수있는 여러 텍스트 필드를 저장할 수 있습니다.

0

배열 기반 실행 취소 시스템을 만듭니다. 클립 보드를 사용하지 마십시오. 작동하지 않습니다.

관련 문제