ソースコード
数時間で作ったので1ファイルだけです。
note.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onInit()"> <mx:XML format="e4x" id="xmlData"> <root> <menuitem label="ファイル"> <menuitem label="新規作成" value="onNew"/> <menuitem label="開く" value="onOpen"/> <menuitem label="保存" value="onSave"/> <menuitem label="名前をつけて保存" value="onSaveAs"/> </menuitem> <menuitem label="設定"> <menuitem label="エンコーディング"> <menuitem type="radio" groupName="encode" toggled="true" label="UTF-8" value="UTF-8"/> <menuitem type="radio" groupName="encode" toggled="false" label="Shift_JIS" value="Shift_JIS"/> <menuitem type="radio" groupName="encode" toggled="false" label="EUC-JP" value="EUC-JP"/> </menuitem> </menuitem> </root> </mx:XML> <mx:VBox width="100%" height="100%"> <mx:MenuBar id="mnb" dataProvider="{xmlData}" showRoot="false" labelField="@label" itemClick="onMenuClick(event)"/> <mx:TextArea width="100%" id="txtarea" height="100%"/> </mx:VBox> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.MenuEvent; import flash.filesystem.*; import mx.events.CloseEvent; private var _encoding:String = "Shift_JIS"; private var file:File = null; private var currentDir:File = null; /** * ドラッグ&ドロップされたファイルを開くようにする */ public function enableDrag():void{ addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragEnter); addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDragDrop); } public function onDragEnter(evt:NativeDragEvent):void{ trace("onDragEnter"); NativeDragManager.acceptDragDrop(this); } public function onDragDrop(evt:NativeDragEvent):void{ var result:String = "DragDrop\n"; var fileList:Array = evt.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array; trace("onDragDrop drag filenum="+fileList.length); file = fileList[0]; trace("file="+fileList[0].nativePath); fileOpen(); } public function onAskedReOpen(e:CloseEvent):void{ trace("onAskedReOpen:"+e.detail); if( e.detail == Alert.YES ){ fileOpen() } } /** * メニュー選択 */ private function onMenuClick(e:MenuEvent):void{ var l:String = e.item.@value; debug(l); if( l == "UTF-8" || l == "EUC-JP" || l == "Shift_JIS"){ _encoding = l; if( file ){ mx.controls.Alert.show( "ファイルを読み込み直しますか?","エンコーディングを"+_encoding+"にしました", Alert.YES | Alert.NO, this, onAskedReOpen, null, Alert.NO); } } if( l == "onOpen" ){ onOpen(); } if( l == "onSave" ){ onSave(); } if( l == "onSaveAs" ){ onSaveAs(); } if( l == "onNew" ){ onNew(); } } private function onInit():void{ // 起動パラメータの処理 NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke); // ドラッグドロップされたファイルを開くように設定 enableDrag(); } /** * 起動時に呼ばれる。 */ private function onInvoke(e:InvokeEvent):void{ currentDir = e.currentDirectory; if( ! e.arguments.length ) return; // アイコンにドロップして起動した時など、パラメータがあるとき // ファイルを開く var s:String = e.arguments[0]; debug("onInvoke:arg1="+s); file = new File(s); if( ! file.exists ){ alert("指定されたファイルは存在しません"); }else{ fileOpen(); } } private function onNew():void{ trace("onNew"); file = null; txtarea.text = ""; } private function onSave():void{ if( ! file ){ trace("ファイルが選択されていないため名前をつけて保存"); onSaveAs(); return; } var stream:FileStream = new FileStream(); stream.open(file, FileMode.WRITE); var txt:String = txtarea.text; stream.writeMultiByte(txt, _encoding); stream.close(); alert("保存しました"); } private function onSaveAs():void{ file = new File(); file.addEventListener(Event.SELECT, onFileSelectForSave); file.browseForSave("保存先を選択"); } private function onFileSelectForSave(e:Event):void{ debug("onFileSelectedForSave:"+file.url); onSave(); } private function alert(s:String):void{ Alert.show(s); } /** * file open */ private function onOpen():void{ debug("onOpen"); file = new File(); file.addEventListener(Event.SELECT, fileOpen); file.browseForOpen("ファイルを選択"); } private function fileOpen(e:Event = null):void{ debug("fileOpen:"+file.url); var stream:FileStream = new FileStream(); stream.open(file, FileMode.READ); var txt:String = stream.readMultiByte(file.size, _encoding); stream.close(); txtarea.text = txt; } private function debug(s:String):void{ trace("[debug]"+s); } ]]> </mx:Script> </mx:WindowedApplication>
追記:UTF-8しか扱えなかったのでShit_JIS,EUC-JP,UTF-8を扱えるようにしました。エンコーディングを変えてから保存すると文字コードの変換もできます。