チェンジセット 736

差分発生行の前後
無視リスト:
コミット日時:
2008/07/01 22:04:36 (2 ヶ月前)
コミッタ:
yossy
ログメッセージ:

Thread: FileUploadThread? とそのサンプル追加

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Thread/trunk/Thread.as3proj

    r726 r736  
    6969  <!-- Class files to compile (other referenced classes will automatically be included) --> 
    7070  <compileTargets> 
    71     <compile path="tests\RunTests.as" /> 
     71    <compile path="samples\fileUpload\Sample.as" /> 
    7272  </compileTargets> 
    7373  <!-- Paths to exclude from the Project Explorer tree --> 
  • as3/Thread/trunk/src/org/libspark/thread/threads/net/FileUploadThread.as

    r733 r736  
    4343         
    4444        /** 
    45          * URLLoader を用いてデータを読み込むためのスレッドです. 
     45         * FileReference を用いてファイルをアップロードするためのスレッドです. 
    4646         *  
    47          * <p>このスレッドを開始すると、与えられた URLRequest を用いてロード処理を開始し、 
     47         * <p>このスレッドを開始すると、与えられた URLRequest を用いてアップロード処理を開始し、 
    4848         * ロードが完了 (Event.COMPLETE) するとスレッドが終了します。</p> 
    4949         *  
     
    5858         * </ul> 
    5959         *  
     60         * @author      seagirl 
    6061         * @author      yossy:beinteractive 
    6162         */ 
    62         public class FileReferenceThread extends Thread implements IProgressNotifier 
     63        public class FileUploadThread extends Thread implements IProgressNotifier 
    6364                { 
    6465                        /** 
     
    6768                         * @param request ロード対象となる URLRequest 
    6869                         * @param fileReference ロードに使用する FileReference 。省略もしくは null の場合、新たに作成した FileReference を使用します 
    69                          */ 
    70                         public function FileReferenceThread(request:URLRequest, fileReference:FileReference = null) 
     70                         * @param       updateDataFieldName     アップロードの POST に使用するフィールド名。詳しくは FileReference.upload を参照してください 
     71                         * @param       testUpload      アップロードのテストをするかどうか。詳しくは FileReference.upload を参照してください 
     72                         * @param       waitCompleteData        DataEvent.UPLOAD_COMPLETE_DATA を待ってスレッドを終了するのであれば true そうでなければ false 
     73                         * @param       doBrowse        アップロードの前に browse メソッドを呼び出すのであれば true、そうでなければ false 
     74                         * @param       typeFilter      doBrowse が true の場合、拡張子フィルタ。詳しくは FileReference.browse を参照してください 
     75                         */ 
     76                        public function FileUploadThread(request:URLRequest, fileReference:FileReference = null, uploadDataFieldName:String = "Filedata", testUpload:Boolean = false, waitCompleteData:Boolean = false, doBrowse:Boolean = true, typeFilter:Array = null) 
    7177                        { 
    7278                                _request = request; 
    7379                                _fileReference = fileReference != null ? fileReference : new FileReference(); 
     80                                _uploadDataFieldName = uploadDataFieldName; 
     81                                _testUpload = testUpload; 
     82                                _waitCompleteData = waitCompleteData; 
     83                                _doBrowse = doBrowse; 
     84                                _typeFilter = typeFilter; 
    7485                                _progress = new Progress(); 
    7586                        } 
     
    7788                        private var _request:URLRequest; 
    7889                        private var _fileReference:FileReference; 
    79                         private var _typeFilter:Array = null; 
    80                         private var _uploadDataFieldName:String = 'Filedata'; 
     90                        private var _uploadDataFieldName:String; 
     91                        private var _testUpload:Boolean; 
     92                        private var _waitCompleteData:Boolean; 
     93                        private var _doBrowse:Boolean; 
     94                        private var _typeFilter:Array; 
    8195                        private var _progress:Progress; 
    8296                         
     
    98112                         
    99113                        /** 
    100                          * ダイアログボックスに表示するファイルをフィルタにかける場合に使用する FileFilter インスタンスの配列です。 
     114                         * アップロードの POST に使用するフィールド名。詳しくは FileReference.upload を参照してください. 
     115                         */ 
     116                        public function get uploadDataFieldName():String 
     117                        { 
     118                                return _uploadDataFieldName; 
     119                        } 
     120                         
     121                        /** 
     122                         * @private 
     123                         */ 
     124                        public function set uploadDataFieldName(value:String):void 
     125                        { 
     126                                _uploadDataFieldName = value; 
     127                        } 
     128                         
     129                        /** 
     130                         * アップロードのテストをするかどうか。詳しくは FileReference.upload を参照してください. 
     131                         */ 
     132                        public function get testUpload():Boolean 
     133                        { 
     134                                return _testUpload; 
     135                        } 
     136                         
     137                        /** 
     138                         * @private 
     139                         */ 
     140                        public function set testUpload(value:Boolean):void 
     141                        { 
     142                                _testUpload = value; 
     143                        } 
     144                         
     145                        /** 
     146                         * DataEvent.UPLOAD_COMPLETE_DATA を待ってスレッドを終了するのであれば true そうでなければ false を設定します. 
     147                         */ 
     148                        public function get waitCompleteData():Boolean 
     149                        { 
     150                                return _waitCompleteData; 
     151                        } 
     152                         
     153                        /** 
     154                         * @private 
     155                         */ 
     156                        public function set waitCompleteData(value:Boolean):void 
     157                        { 
     158                                _waitCompleteData = value; 
     159                        } 
     160                         
     161                        /** 
     162                         * アップロードの前に browse メソッドを呼び出すのであれば true、そうでなければ false を設定します. 
     163                         */ 
     164                        public function get doBrowse():Boolean 
     165                        { 
     166                                return _doBrowse; 
     167                        } 
     168                         
     169                        /** 
     170                         * @private 
     171                         */ 
     172                        public function set doBrowse(value:Boolean):void 
     173                        { 
     174                                _doBrowse = value; 
     175                        } 
     176                         
     177                        /** 
     178                         * doBrowse が true の場合、拡張子フィルタ。詳しくは FileReference.browse を参照してください. 
    101179                         */ 
    102180                        public function get typeFilter():Array 
     
    105183                        } 
    106184                         
     185                        /** 
     186                         * @private 
     187                         */ 
    107188                        public function set typeFilter(value:Array):void 
    108189                        { 
     
    111192                         
    112193                        /** 
    113                          * アップロード POST 操作のファイルデータに先行するフィールド名です。 
    114                          */ 
    115                         public function get uploadDataFieldName():String 
    116                         { 
    117                                 return _uploadDataFieldName; 
    118                         } 
    119                          
    120                         public function set uploadDataFieldName(value:String):void 
    121                         { 
    122                                 _uploadDataFieldName = value; 
    123                         } 
    124                          
    125                          
    126                         /** 
    127194                         * @inheritDoc 
    128195                         */ 
     
    133200                         
    134201                        /** 
    135                          * ロード処理をキャンセルします. 
     202                         * アップロード処理をキャンセルします. 
    136203                         */ 
    137204                        public function cancel():void 
     
    147214                         */ 
    148215                        override protected function run():void 
     216                        { 
     217                                // browse メソッド呼び出しが要求されている場合 
     218                                if (doBrowse) { 
     219                                        // 呼び出す 
     220                                        browse(); 
     221                                } 
     222                                else { 
     223                                        // そうでなければアップロード 
     224                                        upload(); 
     225                                } 
     226                        } 
     227                         
     228                        /** 
     229                         * browse メソッド呼び出し 
     230                         *  
     231                         * @private 
     232                         */ 
     233                        private function browse():void 
     234                        { 
     235                                // browse 呼び出し 
     236                                if (fileReference.browse(typeFilter)) { 
     237                                        // 成功の場合イベントハンドラ設定 
     238                                        event(fileReference, Event.SELECT, browseSelectHandler); 
     239                                        event(fileReference, Event.CANCEL, browseCancelHandler); 
     240                                } 
     241                                else { 
     242                                        // 失敗の場合キャンセルと同等の処理をする 
     243                                        browseCancelHandler(null); 
     244                                } 
     245                        } 
     246                         
     247                        /** 
     248                         * browse 選択ハンドラ 
     249                         *  
     250                         * @private 
     251                         */ 
     252                        private function browseSelectHandler(e:Event):void 
     253                        { 
     254                                // 選択されたらアップロードする 
     255                                upload(); 
     256                        } 
     257                         
     258                        /** 
     259                         * browse キャンセルハンドラ 
     260                         *  
     261                         * @private 
     262                         */ 
     263                        private function browseCancelHandler(e:Event):void 
     264                        { 
     265                                // とりあえず開始したことにして 
     266                                _progress.start(0); 
     267                                // すぐキャンセル 
     268                                _progress.cancel(); 
     269                                // して終わり 
     270                        } 
     271                         
     272                        /** 
     273                         * アップロード 
     274                         *  
     275                         * @private 
     276                         */ 
     277                        private function upload():void 
    149278                        { 
    150279                                // イベントハンドラを設定 
     
    155284                                interrupted(interruptedHandler); 
    156285                                 
    157                                 // ロード開始 
    158                                 _fileReference.browse(typeFilter); 
     286                                // アップロード開始 
     287                                fileReference.upload(request, uploadDataFieldName, testUpload); 
    159288                        } 
    160289                         
     
    166295                        private function events():void 
    167296                        { 
    168                                 event(_fileReference, DataEvent.UPLOAD_COMPLETE_DATA, completeHandler); 
    169                                 event(_fileReference, ProgressEvent.PROGRESS, progressHandler); 
    170                                 event(_fileReference, IOErrorEvent.IO_ERROR, ioErrorHandler); 
    171                                 event(_fileReference, SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
     297                                if (waitCompleteData) { 
     298                                        event(fileReference, DataEvent.UPLOAD_COMPLETE_DATA, completeHandler); 
     299                                } 
     300                                else { 
     301                                        event(fileReference, Event.COMPLETE, completeHandler); 
     302                                } 
     303                                event(fileReference, ProgressEvent.PROGRESS, progressHandler); 
     304                                event(fileReference, IOErrorEvent.IO_ERROR, ioErrorHandler); 
     305                                event(fileReference, SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
    172306                        } 
    173307                         
     
    185319                         
    186320                        /** 
    187                          * Event.SELECT ハンドラ 
    188                          *  
    189                          * @private 
    190                          */ 
    191                         private function selectHandler(e:Event):void 
    192                         { 
    193                                 _fileReference.upload(_request, uploadDataFieldName); 
    194                         } 
    195                          
    196                          
    197                         /** 
    198321                         * ProgressEvent.PROGRESS ハンドラ 
    199322                         *  
     
    275398                                notifyStartIfNeeded(0); 
    276399                                 
    277                                 // ロードをキャンセル 
    278                                 _fileReference.cancel(); 
     400                                // アップロードをキャンセル 
     401                                fileReference.cancel(); 
    279402                                 
    280403                                // キャンセルを通知