public class UndoTextArea extends TextArea { private var _undoManager:UndoManager; public function UndoTextArea() { super(); _undoManager=new UndoManager(); this.addEventListener(KeyboardEvent.KEY_UP,undoKeyUpHandler); this.addEventListener(FlexEvent.CREATION_COMPLETE,creationCompleteHandler); } private function creationCompleteHandler(evt:FlexEvent):void { this.textFlow.interactionManager=new EditManager(this._undoManager); } private function undoKeyUpHandler(evt:KeyboardEvent):void { if (evt.ctrlKey&&evt.keyCode == 90) { _undoManager.undo(); } } }
这里使用了KEY_UP事件,其实更合理的是用KEY_DOWN,只是在IE下CTRL-Z被浏览器截获了,我们的程序捕获不到!