| | 3 | <mx:Script> |
|---|
| | 4 | <![CDATA[ |
|---|
| | 5 | import mx.controls.Alert; |
|---|
| | 6 | import mx.core.Application; |
|---|
| | 7 | import mx.managers.PopUpManager; |
|---|
| | 8 | |
|---|
| | 9 | private static const ALERT_TITLE:String = "ふっかつのじゅもん"; |
|---|
| | 10 | |
|---|
| | 11 | public function set password(value:String):void |
|---|
| | 12 | { |
|---|
| | 13 | passwordTextArea.text = value; |
|---|
| | 14 | } |
|---|
| | 15 | |
|---|
| | 16 | private function onClipboard():void |
|---|
| | 17 | { |
|---|
| | 18 | System.setClipboard(passwordTextArea.text); |
|---|
| | 19 | } |
|---|
| | 20 | |
|---|
| | 21 | private function onSave():void |
|---|
| | 22 | { |
|---|
| | 23 | if (passwordTextArea.text.length > 0) { |
|---|
| | 24 | var bytes:ByteArray = new ByteArray(); |
|---|
| | 25 | Application.application.save(bytes, passwordTextArea.text); |
|---|
| | 26 | createFileReferenceEvents(); |
|---|
| | 27 | m_file.addEventListener(Event.SELECT, onSelectSave); |
|---|
| | 28 | m_file.addEventListener(Event.COMPLETE, onSaveComplete); |
|---|
| | 29 | m_file.save(bytes); |
|---|
| | 30 | } |
|---|
| | 31 | else { |
|---|
| | 32 | Alert.show("パスワードが入力されていません", ALERT_TITLE); |
|---|
| | 33 | } |
|---|
| | 34 | } |
|---|
| | 35 | |
|---|
| | 36 | private function onLoad():void |
|---|
| | 37 | { |
|---|
| | 38 | if (passwordTextArea.text.length > 0) { |
|---|
| | 39 | createFileReferenceEvents(); |
|---|
| | 40 | m_file.addEventListener(Event.SELECT, onSelectLoad); |
|---|
| | 41 | m_file.addEventListener(Event.COMPLETE, onLoadComplete); |
|---|
| | 42 | m_file.browse(); |
|---|
| | 43 | } |
|---|
| | 44 | else { |
|---|
| | 45 | Alert.show("パスワードが入力されていません", ALERT_TITLE); |
|---|
| | 46 | } |
|---|
| | 47 | } |
|---|
| | 48 | |
|---|
| | 49 | private function onSelectLoad(event:Event):void |
|---|
| | 50 | { |
|---|
| | 51 | var file:FileReference = FileReference(event.target); |
|---|
| | 52 | file.load(); |
|---|
| | 53 | currentState = "progress"; |
|---|
| | 54 | } |
|---|
| | 55 | |
|---|
| | 56 | private function onSelectSave(event:Event):void |
|---|
| | 57 | { |
|---|
| | 58 | currentState = "progress"; |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | private function onLoadComplete(event:Event):void |
|---|
| | 62 | { |
|---|
| | 63 | var file:FileReference = FileReference(event.target); |
|---|
| | 64 | var bytes:ByteArray = file.data; |
|---|
| | 65 | currentState = ""; |
|---|
| | 66 | Application.application.load(bytes, passwordTextArea.text); |
|---|
| | 67 | removeFileReference(); |
|---|
| | 68 | } |
|---|
| | 69 | |
|---|
| | 70 | private function onSaveComplete(event:Event):void |
|---|
| | 71 | { |
|---|
| | 72 | currentState = ""; |
|---|
| | 73 | removeFileReference(); |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| | 76 | private function onCancel(event:Event):void |
|---|
| | 77 | { |
|---|
| | 78 | removeFileReference(); |
|---|
| | 79 | } |
|---|
| | 80 | |
|---|
| | 81 | private function onProgress(event:ProgressEvent):void |
|---|
| | 82 | { |
|---|
| | 83 | progress.setProgress(event.bytesLoaded, event.bytesTotal); |
|---|
| | 84 | } |
|---|
| | 85 | |
|---|
| | 86 | private function onError(event:ErrorEvent):void |
|---|
| | 87 | { |
|---|
| | 88 | Alert.show(event.text, ALERT_TITLE); |
|---|
| | 89 | removeFileReference(); |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | private function createFileReferenceEvents():void |
|---|
| | 93 | { |
|---|
| | 94 | m_file = new FileReference(); |
|---|
| | 95 | m_file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError); |
|---|
| | 96 | m_file.addEventListener(IOErrorEvent.IO_ERROR, onError); |
|---|
| | 97 | m_file.addEventListener(ProgressEvent.PROGRESS, onProgress); |
|---|
| | 98 | m_file.addEventListener(Event.CANCEL, onCancel); |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| | 101 | private function removeFileReference():void |
|---|
| | 102 | { |
|---|
| | 103 | m_file.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onError); |
|---|
| | 104 | m_file.removeEventListener(IOErrorEvent.IO_ERROR, onError); |
|---|
| | 105 | m_file.removeEventListener(ProgressEvent.PROGRESS, onProgress); |
|---|
| | 106 | m_file.removeEventListener(Event.CANCEL, onCancel); |
|---|
| | 107 | m_file.removeEventListener(Event.SELECT, onSelectLoad); |
|---|
| | 108 | m_file.removeEventListener(Event.SELECT, onSelectSave); |
|---|
| | 109 | m_file.removeEventListener(Event.COMPLETE, onLoadComplete); |
|---|
| | 110 | m_file.removeEventListener(Event.COMPLETE, onSaveComplete); |
|---|
| | 111 | m_file = null; |
|---|
| | 112 | PopUpManager.removePopUp(this); |
|---|
| | 113 | } |
|---|
| | 114 | |
|---|
| | 115 | private var m_file:FileReference; |
|---|
| | 116 | ]]> |
|---|
| | 117 | </mx:Script> |
|---|
| | 118 | <mx:states> |
|---|
| | 119 | <mx:State name="progress"> |
|---|
| | 120 | <mx:SetProperty target="{progress}" name="visible" value="true"/> |
|---|
| | 121 | </mx:State> |
|---|
| | 122 | </mx:states> |
|---|
| 4 | | <mx:Button id="setClipboardButton" x="10" y="274" label="クリップボードにコピー" click="copyToClipboard()"/> |
|---|
| 5 | | <mx:Button id="deserializeButton" x="7" y="138" label="ふっかつする" click="deserialize()"/> |
|---|
| 6 | | <mx:Script> |
|---|
| 7 | | import flash.system.System; |
|---|
| 8 | | |
|---|
| 9 | | import mx.core.Application; |
|---|
| 10 | | import mx.managers.PopUpManager; |
|---|
| 11 | | |
|---|
| 12 | | import org.libspark.gunyarapaint.ui.v1.Canvas; |
|---|
| 13 | | |
|---|
| 14 | | public function set password(s:String):void { |
|---|
| 15 | | passwordTextArea.text = s; |
|---|
| 16 | | } |
|---|
| 17 | | public function copyToClipboard():void { |
|---|
| 18 | | System.setClipboard(passwordTextArea.text); |
|---|
| 19 | | } |
|---|
| 20 | | public function deserialize():void { |
|---|
| 21 | | Application.application.deserialize(passwordTextArea.text); |
|---|
| 22 | | PopUpManager.removePopUp(this); |
|---|
| 23 | | } |
|---|
| 24 | | </mx:Script> |
|---|
| | 124 | <mx:Button id="setClipboardButton" x="124.5" y="274" label="クリップボードにコピー" click="onClipboard()"/> |
|---|
| | 125 | <mx:Button id="deserializeButton" x="10" y="274" label="ふっかつする" click="onLoad()"/> |
|---|
| | 126 | <mx:Button x="290" y="274" label="ほぞんする" click="onSave()"/> |
|---|
| | 127 | <mx:ProgressBar x="10" y="238" width="360" enabled="true" id="progress" visible="false"/> |
|---|