| <?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="initApp()"
backgroundColor="0xFFFFFF"
horizontalAlign="left"
paddingLeft="0"
paddingTop="0"
paddingBottom="0"
paddingRight="0"
viewSourceURL="http://winofsql.jp/VA003334/flex2071208145032.htm"
>
<mx:Style>
@font-face {
src: local("HGP創英角ポップ体");
fontFamily: HGP;
fontWeight: bold;
unicodeRange:
U+0030-U+0039,
U+30A6-U+30FC,
U+0044-U+0044,
U+0025-U+0025,
U+003A-U+003A,
U+0043-U+0043,
U+002C-U+002C,
U+002E-U+002E,
U+5B8C-U+5B8C,
U+4E86-U+4E86,
U+0061-U+007A;
}
global {
font-family: HGP;
fontSize: 11px;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.utils.ObjectUtil;
import flash.events.*;
import flash.net.*;
private var targetDir:String;
private var targetFile:String;
private var targetExt:String;
private var fr:FileReference;
private var size:String = "";
private function initApp():void {
var param:Object = mx.core.Application.application.parameters;
targetDir = param['dir'];
if ( targetDir == null || targetDir == "" ) {
targetDir = "file";
}
targetFile = param['file'];
if ( targetFile == null || targetFile == "" ) {
targetFile = "readme";
}
targetExt = param['ext'];
if ( targetExt == null ) {
targetExt = "txt";
}
fr = new FileReference();
// IO エラー
fr.addEventListener(IOErrorEvent.IO_ERROR, systemError);
// セキュリティエラー
fr.addEventListener(SecurityErrorEvent.SECURITY_ERROR, dummy);
// 処理終了
fr.addEventListener(Event.COMPLETE, completeUpload);
// 処理中
fr.addEventListener(ProgressEvent.PROGRESS, progressDownload);
// キャンセル
fr.addEventListener(Event.CANCEL, cancelDownload);
}
// *************************************************
// 処理中
// *************************************************
private function progressDownload(event:ProgressEvent):void {
// ダウンロード済みと最終データ量から進行状況をセット
progressBar.setProgress(
event.bytesLoaded,
event.bytesTotal
);
// ラベルの表示
if ( event.bytesTotal != 0 ) {
size = nFormatter.format(event.bytesTotal);
progressBar.label =
"Downloading " +
int((event.bytesLoaded/event.bytesTotal)*100) +
"% : " + size;
}
}
// *************************************************
// 処理終了
// *************************************************
private function completeUpload(event:Event):void {
progressBar.label = "ダウンロード完了 : " + size;
}
// *************************************************
// 処理開始
// *************************************************
private function startDownload():void {
var req:URLRequest = new URLRequest();
req.url = targetDir+"/"+targetFile+"."+targetExt;
req.method = URLRequestMethod.GET;
// プログレスバーの初期化
progressBar.setProgress(0, 100);
size = "";
// ダウンロード
fr.download(req);
}
// *************************************************
// IO エラー
// *************************************************
private function systemError(event:IOErrorEvent):void{
Alert.show("IOError:" + event.text);
}
// *************************************************
// ファイル選択のキャンセル
// *************************************************
private function cancelDownload(event:Event):void {
}
// *************************************************
// ダミー
// *************************************************
private function dummy(event:SecurityErrorEvent):void {
Alert.show("Security Error:" + event.text);
}
]]>
</mx:Script>
<!-- *********************************** -->
<!-- カンマ編集用非表示オブジェクト -->
<!-- *********************************** -->
<mx:NumberFormatter
id="nFormatter"
useThousandsSeparator="true"
/>
<mx:VBox>
<!-- *********************************** -->
<!-- ファイル選択 -->
<!-- *********************************** -->
<mx:Button
width="100%"
label="ダウンロード"
click="startDownload();"
/>
<!-- *********************************** -->
<!-- 実行中のプログレスバー -->
<!-- *********************************** -->
<mx:ProgressBar
id="progressBar"
mode="manual"
label="Downloading 0%"
/>
</mx:VBox>
</mx:Application>
| |