| <?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initData();"
applicationComplete="initApplication()"
>
<mx:Style source="Style.css" />
<mx:Script>
<![CDATA[
import mx.controls.*;
import mx.events.*;
import mx.formatters.*;
import flash.external.*;
private var img:Array;
private var counter:int = 0;
private var myImageLoader:Loader;
private var myWriter:SimpleFlvWriter;
// アップロード用
private var post:URLLoader;
// ローカル保存用
private var fRef: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 {
// 別ドメインの JavaScript からの呼び出しを許可する
Security.allowDomain("*");
// パラメータをプロパティとして持つ Object を取得
var param:Object = mx.core.Application.application.parameters;
}
// *********************************************************
// アプリケーションの初期化( 画面関係の初期化終了後 )
// *********************************************************
public function initApplication():void {
}
// *********************************************************
// FLV 作成開始
// *********************************************************
public function createFlv():void {
firebug("処理開始");
img = new Array();
img.push( "image/001.jpg" );
img.push( "image/002.jpg" );
img.push( "image/003.jpg" );
// アップロード用のインスタンス
post = new URLLoader();
// FLV 作成用
myWriter = SimpleFlvWriter.getInstance();
// 新規
myWriter.fs = new ByteArray();
// 1秒間に1フレーム
myWriter.createFile(650, 490, 0.1); // 10秒間に1フレーム
// ローダを作成してイベント登録して、最初の呼び出し
myImageLoader = new Loader();
myImageLoader.contentLoaderInfo.addEventListener(
Event.COMPLETE,loadImageAction);
loadImage(); // 2回目以降は、イベント内から呼び出される
// ローカル保存用インスタンス
fRef = new FileReference();
fRef.addEventListener(Event.OPEN,
function(e:Event):void {} );
fRef.addEventListener(ProgressEvent.PROGRESS,
function(e:ProgressEvent):void {} );
fRef.addEventListener(Event.COMPLETE, function(e:Event):void {
firebug( "COMPLETE" );
} );
fRef.addEventListener(Event.CANCEL,
function(e:Event):void {} );
fRef.addEventListener(Event.SELECT,
function(e:Event):void {
firebug( "保存します" );
} );
fRef.addEventListener(IOErrorEvent.IO_ERROR, fRefError );
}
// *********************************************************
// IOエラー
// *********************************************************
public function fRefError( e:IOErrorEvent ):void {
Alert.show(e.text);
}
// *********************************************************
// PC のローカル保存( イベント内からは実行できない )
// *********************************************************
public function fRefSave():void {
try {
fRef.save( myWriter.fs, "images.flv" );
}
catch( e:Error ) {
firebug( e );
}
}
// *********************************************************
// ロード開始の指令関数
// *********************************************************
public function loadImage():void {
// URL を設定してロード開始
var request:URLRequest = new URLRequest( img[counter] );
myImageLoader.load(request);
}
// *********************************************************
// 一つの画像の読み込み完了
// *********************************************************
public function loadImageAction(e:Event):void {
myWriter.saveFrame( e.target.content.bitmapData );
// 次のロードの為にカウンタをインクリメント
counter++;
if ( counter == 3 ) {
// 全てロード完了
firebug("completed")
// 全て完了しているので、終了処理
myWriter.closeFile()
var req:URLRequest = new URLRequest("./writeflv.php");
// PHP に送る FLV データをセット
req.data = myWriter.fs;
req.method = URLRequestMethod.POST;
post.load(req);
saveLocalFlv.enabled = true;
}
else {
firebug("next")
// 次の画像を読み込む
loadImage();
}
}
]]>
</mx:Script>
<mx:VBox width="100%">
<mx:Button
id="startCreateFlv"
label="処理開始"
click="createFlv();"
width="130"
/>
<mx:Button
id="saveLocalFlv"
label="PC保存"
click="fRefSave();"
width="130"
enabled="false"
/>
</mx:VBox>
</mx:Application>
| |