会津えろうそくまつりアプリをリリースしました〜


会津えろうそくまつりアプリをリリースしました〜
http://www.aizu-shop.com/kuratto/erousoku2011/
アプリのインストールはこちら
https://market.android.com/details?id=air.erousokuCharaCamera2

ソースコードはこちら

なんだかGalaxyTabだと動作が遅いです(^^;

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        actionBarVisible="false" contentBackgroundColor="#000000"
        creationComplete="view1_creationCompleteHandler(event)" overlayControls="false"
        tabBarVisible="false" title="Home">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import cmodule.aircall.CLibInit;
            //キャラクター画像リスト
            [Embed(source="assets/01.png")]private var image_01:Class;
            [Embed(source="assets/02.png")]private var image_02:Class;
            [Embed(source="assets/03.png")]private var image_03:Class;
            [Embed(source="assets/04.png")]private var image_04:Class;
            [Embed(source="assets/05.png")]private var image_05:Class;
            //カメラ作成
            private var cam:Camera;
            protected function view1_creationCompleteHandler(event:FlexEvent):void
            {
//                if( Camera.isSupported ){
                    cam = Camera.getCamera();
                    cam.setMode(640,480,5);
                    var vd:Video =  new Video(cam.width,cam.height);
                    vd.rotation = 90;
                    vd.x = 480;
                    vd.attachCamera(cam);
                    myUI.addChild(vd);
//                }else{
//                }
            }
            //キャラクター変更
            private var i:int = 1;
            protected function charactor_clickHandler(event:MouseEvent):void
            {
                i++;
                if( i > 5 ){
                    i=1;
                }
                charactor.source = this["image_0"+i];
                charactorShow.play();
                soundCharactor.play();
            }
            //カメラキャプチャー
            private var lib : Object;
            private var init:CLibInit;
            private var baout:ByteArray;
            private var ba:ByteArray;
            //画像をJPGエンコード
            protected function captureBtn_clickHandler(event:MouseEvent):void
            {
                //メッセージの表示
                messageBase.visible = true;
                messageTxt.text = "画像を保存しています";
                soundCapture.play();
                //Alchemyの準備
                init = new CLibInit();
                lib = init.init();
                baout = new ByteArray();
                //キャンバスの描画
                var bmd:BitmapData = new BitmapData(480,640);
                bmd.draw(canvas);
                ba = bmd.getPixels( new Rectangle(0,0,480,640) );
                ba.position = 0;
                if ( baout ){
                    baout.clear();
                }else{
                    baout = new ByteArray();
                }
                //キャプチャーされた画像を表示しておく(プレビュー)
                caputredImage.source = bmd;
                caputredImage.visible = true;
                //非同期でJPG保存
                lib.encodeAsync( compressFinished, ba, baout, 480 , 640 , 90, 10 );
            }
            //画像をJPGエンコード完了・画像保存
            private var date:Date = new Date();
            private function compressFinished( out:ByteArray ):void
            {
                caputredImage.visible = false;
                //メッセージの表示
                messageTxt.text = "SDカードに保存しました!";
                messageBase.visible = false;
                //画像の保存
                var fileName:String = date.getFullYear() +"_"+ (date.getMonth()+1) +"_"+ date.getDay() +"_"+ date.getHours() +"_"+ date.getMinutes() +"_"+ date.getSeconds() + "_"+ + date.getMilliseconds() + ".jpg";
                var file:File = File.documentsDirectory.resolvePath(fileName);
                var stream:FileStream = new FileStream();
                stream.open(file, FileMode.WRITE);
                stream.writeBytes(baout);
                stream.close();
                soundSaved.play();
                ba.clear();
                baout.position = 0;
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!--サウンドエフェクト-->
        <mx:SoundEffect id="soundCapture"   target="{this}" useDuration="false" source="@Embed('assets/caputer.mp3')"/>
        <mx:SoundEffect id="soundSaved"     target="{this}" useDuration="false" source="@Embed('assets/saved.mp3')"/>
        <mx:SoundEffect id="soundCharactor" target="{this}" useDuration="false" source="@Embed('assets/charactor.mp3')"/>
        <!--表示エフェクト-->
        <s:Sequence id="myFadeShow">
            <s:Fade alphaFrom="0" alphaTo="1" duration="1000"/>
        </s:Sequence>
        <s:Sequence id="myFadeHide">
            <s:Fade alphaFrom="1" alphaTo="0" duration="2000"/>
        </s:Sequence>
        <s:Fade id="charactorShow" alphaFrom="0" alphaTo="1" target="{charactor}"/>
    </fx:Declarations>
    <s:Group width="480" height="760" verticalCenter="0" horizontalCenter="0">
        <!--背景画像など-->
        <s:Image source="@Embed('assets/bg_top.jpg')" top="0"/>
        <s:Image x="0" y="700" source="@Embed('assets/bg_bottom.jpg')"/>
        <!--キャンバス-->
        <s:Group id="canvas" width="480" height="640" y="60">
            <mx:UIComponent id="myUI" width="100%" height="100%"/>
            <s:Image id="charactor" x="207" y="140" source="@Embed('assets/01.png')" click="charactor_clickHandler(event)"/>
            <s:Image id="bg" x="0" y="0" source="@Embed('assets/bg.png')"/>
        </s:Group>
        <!--キャプチャーされた画像表示用-->
        <s:Image id="caputredImage" width="480" height="640" visible="false" y="60" showEffect="Fade" hideEffect="Fade" />
        <!--キャプチャーボタン-->
        <s:Image id="captureBtn" bottom="10" horizontalCenter="0" source="assets/btn.png" click="captureBtn_clickHandler(event)" buttonMode="true" mouseDown="{captureBtn.bottom=2}" mouseUp="{captureBtn.bottom=10}"/>
        <!--メッセージボックス-->
        <s:Group id="messageBase" horizontalCenter="0" verticalCenter="0" visible="false" showEffect="myFadeShow" hideEffect="myFadeHide" click="{messageBase.visible=false;}">
            <s:Rect width="400" height="102" radiusX="10" radiusY="10">
                <s:fill>
                    <s:SolidColor color="0xffccff" alpha="0.8"/>
                </s:fill>
            </s:Rect>
            <s:Label id="messageTxt" text="" horizontalCenter="0" verticalCenter="0" color="0xd900bd"/>
        </s:Group>
    </s:Group>
</s:View>

参考になるページ

読み込み可能なMP3ファイルのフォーマット - 独学ActionScript
WavからMP3へエンコードする際に注意。今回起動音でコンパイルエラーが出ました。
asynchronous jpeg encoding
同期・非同期でJPGエンコードが可能。動作も早い
alchemyJpeg.mxml
AlchemyなJPEGエンコードのサンプル