| <?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initData();"
applicationComplete="initApplication()"
paddingLeft="0"
paddingTop="20"
paddingBottom="0"
paddingRight="0"
>
<mx:Style source="Style.css" />
<mx:Script>
<![CDATA[
// *********************************************************
// 【Papervision3D_2.1.920.swc】
// Application の paddingTop と paddingBottom のデフォルト
// は 24 なので注意
// ( 大きさは、HTML 側で決めています )
// *********************************************************
import mx.formatters.*;
//papervision3Dクラスをインポート
import nochump.util.zip.*;
private var loader:URLLoader;
private var saveRef:FileReference;
// *********************************************************
// ログ表示
// *********************************************************
public function firebug(data:Object):void {
var fmt:DateFormatter = new DateFormatter();
fmt.formatString = "YYYY/MM/DD HH:NN:SS";
var logdt:String = fmt.format( new Date );
ExternalInterface.call(
"console.log", logdt,
data+""
);
}
// *********************************************************
// アプリケーションの初期化
// *********************************************************
public function initData():void {
}
// *********************************************************
// アプリケーションの初期化( 画面構築後 )
// *********************************************************
public function initApplication():void {
// ローカルファイル用
saveRef = new FileReference();
// リモートファイル取得用
loader = new URLLoader();
// ByteArray による処理
loader.dataFormat = URLLoaderDataFormat.BINARY;
// イベント登録
loader.addEventListener(Event.COMPLETE,
function(event:Event):void {
firebug( "ロード完了" );
saveButton1.enabled = true;
saveButton2.enabled = true;
}
);
}
// *********************************************************
// ロード
// *********************************************************
public function loadImage():void {
loader.load(
new URLRequest( imageUrl.text )
);
// 表示チェック
imageCheck.source = imageUrl.text;
}
// *********************************************************
// 保存
// *********************************************************
public function saveFile():void {
saveRef.save( loader.data, "save.jpg" );
}
// *********************************************************
// 保存
// *********************************************************
public function saveZipfile():void {
var ze:ZipEntry = new ZipEntry("save.jpg");
var zo:ZipOutput = new ZipOutput();
zo.putNextEntry(ze);
zo.write( loader.data );
zo.closeEntry();
var ba:ByteArray = new ByteArray();
ba.writeMultiByte("この文字列はSHIFT_JIS(CRLF)です","shift_jis");
ba.writeByte(0x0d);
ba.writeByte(0x0a);
ba.writeMultiByte("日本語表示","shift_jis");
ba.writeByte(0x0d);
ba.writeByte(0x0a);
ze = new ZipEntry("readme_sjis.txt");
zo.putNextEntry(ze);
zo.write( ba );
zo.closeEntry();
ba.clear();
ba.writeUTFBytes("この文字列はUTF-8(LF)です");
ba.writeByte(0x0a);
ba.writeUTFBytes("日本語表示");
ba.writeByte(0x0a);
ze = new ZipEntry("readme_utf8n.txt");
zo.putNextEntry(ze);
zo.write( ba );
zo.closeEntry();
zo.finish();
saveRef.save( zo.byteArray, "save.zip" );
}
]]>
</mx:Script>
<mx:Panel
title="Papervision3D_2.1.920 の nochump.util.zip の利用"
horizontalAlign="center"
paddingTop="10"
paddingLeft="0"
paddingRight="0"
paddingBottom="30"
width="600"
>
<mx:Label text="▼URL" />
<mx:TextInput
id="imageUrl"
width="500"
text="http://lightbox.cocolog-nifty.com/photos/image_another/b17eva239.jpg"
/>
<mx:Button
id="loadButton"
label="ロード"
click="loadImage();"
width="200"
/>
<mx:Button
id="saveButton1"
label="URLLoader=>画像保存"
click="saveFile();"
width="200"
enabled="false"
/>
<mx:Button
id="saveButton2"
label="URLLoader=>ZIP保存"
click="saveZipfile();"
width="200"
enabled="false"
/>
<mx:Image
id="imageCheck"
width="200"
height="200"
/>
</mx:Panel>
</mx:Application>
| |