<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" width="920" height="650" initialize="application_initializeHandler()" viewSourceURL="http://kb4102.dip.jp/data/srcviewCreater/index.html">
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        s|TextBase, s|SkinnableTextBase {
            fontFamily: "メイリオ", "ヒラギノ角ゴ Pro W3", "さざなみゴシック", "Takao Pゴシック", "VL Pゴシック", "IPA Pゴシック", "MS Pゴシック", "_sans";
        }
    </fx:Style>
    <s:Label y="638" text="UruLab Creater OS" color="#999999" click="messageClick()"/>
    <s:Button id="about" x="895" y="635" width="25" height="15" label="?" fontSize="8" click="PopUpManager.centerPopUp(PopUpManager.createPopUp(this, AboutUrulab, true))"/>
    <mx:ViewStack id="viewstack" width="100%" height="635" change="viewstack_changeHandler(event)">
        <!-- 形の選択 -->
        <s:NavigatorContent label="view0" width="100%" height="100%">
            <s:Label x="10" y="10" text="器の型を選んでください" fontSize="18"/>
            <mx:Image x="30" y="110" source="@Embed('image/model0.gif')" click="nextView(); _modelURI = 'model/model0.dae'" buttonMode="true"/>
            <mx:Image x="346" y="110" source="@Embed('image/model1.gif')" click="nextView(); _modelURI = 'model/model1.dae'" buttonMode="true"/>
            <mx:Image x="646" y="110" source="@Embed('image/model2.gif')" click="nextView(); _modelURI = 'model/model2.dae'" buttonMode="true"/>
            <mx:Image x="160" y="380" source="@Embed('image/model3.gif')" click="nextView(); _modelURI = 'model/model3.dae'" buttonMode="true"/>
            <mx:Image x="540" y="380" source="@Embed('image/model4.gif')" click="nextView(); _modelURI = 'model/model4.dae'" buttonMode="true"/>
        </s:NavigatorContent>
        <!-- 色の選択 -->
        <s:NavigatorContent label="view1" width="100%" height="100%">
            <s:Label x="10" y="10" text="色を選んでください" fontSize="18"/>
            <s:SkinnableContainer name="0xff000000" x="10" y="170" width="150" height="60" backgroundColor="#000000" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="60" y="15" text="" color="#FFFFFF" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xffcc0000" x="160" y="170" width="150" height="60" backgroundColor="#CC0000" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="56" y="15" text="" color="#FFFFFF" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xfff72609" x="310" y="170" width="150" height="60" backgroundColor="#F72609" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="45" y="15" text="洗朱" color="#FFFFFF" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xff02822f" x="460" y="170" width="150" height="60" backgroundColor="#02822F" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="45" y="15" text="青光" color="#FFFFFF" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xff880000" x="610" y="170" width="150" height="60" backgroundColor="#880000" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="30" y="15" text="うるみ" color="#FFFFFF" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xffcccc00" x="760" y="170" width="150" height="60" backgroundColor="#CCCC00" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="60" y="15" text="" color="#FFFFFF" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xffff99ff" x="10" y="400" width="150" height="60" backgroundColor="#FF99FF" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="30" y="15" text="ピンク" color="#333333" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xffff6633" x="160" y="400" width="150" height="60" backgroundColor="#FF6633" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="15" y="15" text="オレンジ" color="#333333" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xff99ff00" x="310" y="400" width="150" height="60" backgroundColor="#99FF00" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="45" y="15" text="黄緑" color="#333333" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xff99ffff" x="460" y="400" width="150" height="60" backgroundColor="#99FFFF" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="60" y="15" text="" color="#333333" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xff999999" x="610" y="400" width="150" height="60" backgroundColor="#999999" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="30" y="15" text="グレー" color="#333333" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
            <s:SkinnableContainer name="0xffffeeaa" x="760" y="400" width="150" height="60" backgroundColor="#FFEEAA" buttonMode="true" click="colorcontainer_clickHandler(event)">
                <s:Label x="15" y="15" text="クリーム" color="#333333" fontSize="30" mouseEnabled="false" fontFamily="serif"/>
            </s:SkinnableContainer>
        </s:NavigatorContent>
        <!-- 編集 -->
        <s:NavigatorContent label="view2" width="100%" height="100%">
            <mx:MenuBar height="20" labelField="@label" itemClick="menubar_itemClickHandler(event)">
                <mx:XMLListCollection>
                    <fx:XMLList>
                        <menuitem label="編集">
                            <menuitem label="元に戻す" action="undo"/>
                            <menuitem label="やり直し" action="redo"/>
                            <menuitem label="拡大" action="zoomin"/>
                            <menuitem label="縮小" action="zoomout"/>
                            <menuitem label="点灯" action="turnon"/>
                            <menuitem label="消灯" action="turnoff"/>
                        </menuitem>
                        <menuitem label="モード">
                            <menuitem label="視点移動" action="view"/>
                            <menuitem label="筆1" action="pen1"/>
                            <menuitem label="筆2" action="pen2"/>
                            <menuitem label="伝統模様" action="bmp"/>
                            <menuitem label="イラスト" action="svg1"/>
                            <menuitem label="卵殻" action="rankaku"/>
                            <menuitem label="消しゴム" action="eraser"/>
                        </menuitem>
                        <menuitem label="ウィンドウ">
                            <menuitem label="ツール" action="showtool"/>
                            <menuitem label="ツール詳細" action="showtool2"/>
                            <menuitem label="カラーパレット" action="showcolor"/>
                            <menuitem label="オブジェクト移動" action="showmove"/>
                        </menuitem>
                        <menuitem label="ヘルプ">
                            <menuitem label="操作方法" enabled="false"/>
                            <menuitem label="うるらぼについて" action="about"/>
                        </menuitem>
                    </fx:XMLList>
                </mx:XMLListCollection>
            </mx:MenuBar>
            <s:SkinnableContainer id="modelViewer" y="20" width="741" height="570" backgroundColor="#DDDDDD">
                <s:SpriteVisualElement id="spe" width="741" height="570"/>
                <s:Label id="mode"/>
            </s:SkinnableContainer>
            <s:TitleWindow id="cameraPopUp" x="600" y="500" width="130" height="115" isPopUp="true" borderVisible="false" skinClass="MyPopUpSkin" title="オブジェクト移動" close="cameraPopUpMove.play()">
                <s:Button x="31" y="10" label="" click="_urulab.cameraUp(10)"/>
                <s:Button x="10" y="35" label="" width="35" click="_urulab.cameraLeft(10)"/>
                <s:Button x="48" y="35" label="" width="35" click="_urulab.cameraReset()"/>
                <s:Button x="86" y="35" label="" width="35" click="_urulab.cameraRight(10)"/>
                <s:Button x="31" y="60" label="" click="_urulab.cameraDown(10)"/>
            </s:TitleWindow>
            <s:TitleWindow id="palettePopUp" x="120" y="535" width="260" height="362" isPopUp="true" borderVisible="false" skinClass="MyPopUpSkin" title="カラーパレット" close="palettePopUpMove.play()">
                <s:List x="10" y="10" width="240" height="20" borderVisible="false" change="_urulab.penColor = _defaultPaletteArray[event.target.selectedIndex]; selectedColor.backgroundFill = new SolidColor(_defaultPaletteArray[event.target.selectedIndex])">
                    <s:layout>
                        <s:HorizontalLayout gap="10"/>
                    </s:layout>
                    <s:dataProvider>
                        <s:ArrayCollection source="{_defaultPaletteArray}"/>
                    </s:dataProvider>
                    <s:itemRenderer>
                        <fx:Component>
                            <s:ItemRenderer>
                                <s:BorderContainer width="20" height="20" backgroundColor="{data}"/>
                            </s:ItemRenderer>
                        </fx:Component>
                    </s:itemRenderer>
                </s:List>
                <s:List id="palette" x="10" y="40" width="240" height="20" borderVisible="false" autoLayout="true" change="_urulab.penColor = _paletteArray[event.target.selectedIndex]; selectedColor.backgroundFill = new SolidColor(_paletteArray[event.target.selectedIndex])">
                    <s:layout>
                        <s:HorizontalLayout gap="10"/>
                    </s:layout>
                    <s:dataProvider>
                        <s:ArrayCollection id="paletteArray" source="{_paletteArray}"/>
                    </s:dataProvider>
                    <s:itemRenderer>
                        <fx:Component>
                            <s:ItemRenderer>
                                <s:BorderContainer width="20" height="20" backgroundColor="{data}"/>
                            </s:ItemRenderer>
                        </fx:Component>
                    </s:itemRenderer>
                </s:List>
                <s:Label x="10" y="70" text="現在の色"/>
                <s:BorderContainer id="selectedColor" x="65" y="69" width="70" height="15" backgroundColor="#FFFFFF"/>
                <s:Button x="10" y="95" label="パレットに追加" click="paletteButton_clickHandler()"/>
                <s:SpriteVisualElement id="cp" x="10" y="125"/>
            </s:TitleWindow>
            <s:TitleWindow id="tool2PopUp" x="625" y="55" width="270" height="200" isPopUp="true" borderVisible="false" skinClass="MyPopUpSkin" title="ツール詳細" close="tool2PopUpMove.play()">
                <mx:ViewStack id="drawView" width="100%" height="100%" creationComplete="drawView_creationCompleteHandler()">
                    <s:NavigatorContent label="default" width="100%" height="100%">
                        <s:Label x="10" y="10" text="ツールを選択してください"/>
                    </s:NavigatorContent>
                    <s:NavigatorContent label="pen" width="100%" height="100%">
                        <s:Label x="10" y="10" text="筆1は通常の線を描くことができます"/>
                        <s:Label x="10" y="30" text="筆2は動かす速さによって太さが変わります"/>
                        <s:Label x="10" y="50" text="太さ"/>
                        <s:HSlider x="10" y="70" width="150" minimum="5" maximum="25" stepSize="1" change="_urulab.penSize = event.target.value"/>
                    </s:NavigatorContent>
                    <s:NavigatorContent label="bmp" width="100%" height="100%">
                        <s:Label x="10" y="10" text="伝統的な模様のスタンプです"/>
                        <s:Label x="10" y="30" text="カラーパレットで色を変更できます"/>
                        <s:List id="bmpList" y="50" width="100%" height="100%" borderVisible="false" change="bmpList_changeHandler(event)">
                            <s:layout>
                                <s:TileLayout columnWidth="120" requestedColumnCount="2"/>
                            </s:layout>
                            <s:dataProvider>
                                <s:ArrayList source="{_bmpStampArray}"/>
                            </s:dataProvider>
                            <s:itemRenderer>
                                <fx:Component>
                                    <s:ItemRenderer>
                                        <s:VGroup>
                                            <mx:Image width="80" height="70" render="img_renderHandler(event)"/>
                                            <s:Label text="{data.name}"/>
                                        </s:VGroup>
                                        <fx:Script>
                                            <![CDATA[
                                                protected function img_renderHandler(event:Event):void
                                                {
                                                    var bmpd:BitmapData = new BitmapData(80, 70, true, 0);
                                                    bmpd.copyPixels(data.bmpd, new Rectangle(0, 0, data.bmpd.width, data.bmpd.height), new Point());
                                                    event.target.source = new Bitmap(bmpd);
                                                }
                                            ]]>
                                        </fx:Script>
                                    </s:ItemRenderer>
                                </fx:Component>
                            </s:itemRenderer>
                        </s:List>
                    </s:NavigatorContent>
                    <s:NavigatorContent label="svg" width="100%" height="100%">
                        <s:Label x="10" y="10" text="イラストのスタンプです"/>
                        <s:Label x="10" y="30" text="ドラッグで変形して貼り付けられます"/>
                        <s:List id="svgList" y="50" width="100%" height="100%" borderVisible="false" change="svgList_changeHandler(event)">
                            <s:layout>
                                <s:TileLayout columnWidth="120" requestedColumnCount="2"/>
                            </s:layout>
                            <s:dataProvider>
                                <s:ArrayList source="{_svgStampArray}"/>
                            </s:dataProvider>
                            <s:itemRenderer>
                                <fx:Component>
                                    <s:ItemRenderer>
                                        <s:VGroup>
                                            <mx:Image width="80" height="70" render="img_renderHandler(event)"/>
                                            <s:Label text="{data.name}"/>
                                        </s:VGroup>
                                        <fx:Script>
                                            <![CDATA[
                                                protected function img_renderHandler(event:Event):void
                                                {
                                                    var bmp:Bitmap = new Bitmap(new BitmapData(80, 70, true, 0));
                                                    var mat:Matrix = new Matrix();
                                                    mat.tx = event.target.width / 2;
                                                    mat.ty = event.target.height / 2;
                                                    bmp.bitmapData.draw(data.sp, mat);
                                                    event.target.source = bmp;
                                                }
                                            ]]>
                                        </fx:Script>
                                    </s:ItemRenderer>
                                </fx:Component>
                            </s:itemRenderer>
                        </s:List>
                    </s:NavigatorContent>
                    <s:NavigatorContent label="eraser" width="100%" height="100%">
                        <s:Label x="10" y="10" text="不要なところを消すことができます"/>
                        <s:Label x="10" y="30" text="太さ"/>
                        <s:HSlider x="10" y="50" width="150" minimum="1" maximum="30" value="5" stepSize="1" change="_urulab.eraserSize = event.target.value"/>
                    </s:NavigatorContent>
                    <s:NavigatorContent label="rankaku" width="100%" height="100%">
                        <s:Label x="10" y="10" text="卵殻模様を描くことができます"/>
                        <s:Label x="10" y="30" text="大きさ"/>
                        <s:HSlider x="10" y="50" width="150" minimum="10" maximum="50" value="15" stepSize="1" change="_urulab.penSize = event.target.value"/>
                    </s:NavigatorContent>
                </mx:ViewStack>
            </s:TitleWindow>
            <s:TitleWindow id="toolPopUp" x="10" y="160" width="92" height="400" isPopUp="true" borderVisible="false" skinClass="MyPopUpSkin" title="ツール" close="toolPopUpMove.play()">
                <s:Button x="10" y="10" width="72" height="32" click="viewButton_clickHandler()" label="視点移動"/>
                <s:Button x="10" y="50" width="32" height="32" click="penButton_clickHandler()" label=""/>
                <s:Button x="50" y="50" width="32" height="32" click="newPenButton_clickHandler()" label=""/>
                <s:Button x="10" y="90" width="72" height="32" click="bmpButton_clickHandler()" label="BMP"/>
                <s:Button x="10" y="130" width="72" height="32" click="svgButton_clickHandler()" label="SVG"/>
                <s:Button x="10" y="170" width="72" height="32" click="materialButton_clickHandler()" label="卵殻"/>
                <s:Button x="10" y="210" width="72" height="32" click="eraserButton_clickHandler()" label="消しゴム"/>
                <mx:HRule x="10" y="250" width="72"/>
                <s:Button x="10" y="260" width="32" height="32" label="+" click="_urulab.zoomIn()"/>
                <s:Button x="50" y="260" width="32" height="32" label="-" click="_urulab.zoomOut()"/>
                <s:Button x="10" y="300" width="72" height="16" label="undo" click="_urulab.undo()"/>
                <s:Button x="10" y="320" width="72" height="16" label="redo" click="_urulab.redo()"/>
                <s:Button x="10" y="340" width="72" height="16" label="on" click="_urulab.lighting = true"/>
                <s:Button x="10" y="360" width="72" height="16" label="off" click="_urulab.lighting = false"/>
            </s:TitleWindow>
        </s:NavigatorContent>
    </mx:ViewStack>
    <fx:Script>
        <![CDATA[
            import frocessing.shape.FShapeSVG;
            
            import mx.controls.Alert;
            import mx.events.CloseEvent;
            import mx.events.IndexChangedEvent;
            import mx.events.MenuEvent;
            import mx.graphics.SolidColor;
            import mx.graphics.codec.PNGEncoder;
            import mx.managers.PopUpManager;
            import mx.rpc.events.ResultEvent;
            
            import net.un_q.utils.KeyCommand;
            
            import spark.events.IndexChangeEvent;
            
            import urulab.fp10.core.UruLabEdit;
            import urulab.fp10.core.UruLabMode;
            import urulab.util.color.UruLabColorPicker;
            
            private const REG:RegExp = new RegExp("[^ -~。-゚]", "g");
            private var _urulab:UruLabEdit;
            private var _modelID:String = null;
            private var _modelURI:String = "";
            private var _color:uint = 0;
            [Bindable]private var _bmpStampArray:Array = [];
            [Bindable]private var _svgStampArray:Array = [];
            [Bindable]private var _svgStampArray2:Array = [];
            [Bindable]private var _defaultPaletteArray:Array = [0, 0xcc0000, 0xf72609, 0x02822f, 0x880000, 0xcccc00, 0xddaa22, 0xcccccc];
            [Bindable]private var _paletteArray:Array = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff];
            private var _ucp:UruLabColorPicker;
            [Embed("sinpi5.mp3")]private var Sound0:Class;
            private var se:Sound = new Sound0() as Sound;
            private var clickCount:uint = 0;
            private var _loaded:Boolean = false;
            private var _con:String = null;
            
            protected function application_initializeHandler():void
            {    
                var loader:URLLoader = new URLLoader();
                loader.addEventListener(Event.COMPLETE, onSvgListComplete);
                loader.load(new URLRequest("http://kb4102.dip.jp/data/svg/svgStampList.xml"));
                var loader2:URLLoader = new URLLoader();
                loader2.addEventListener(Event.COMPLETE, onBmpListComplete);
                loader2.load(new URLRequest("http://kb4102.dip.jp/data/bmp/bmpStampList.xml"));
                
                if(stage)
                    initSE();
                else
                    addEventListener(Event.ADDED_TO_STAGE, initSE);
            }
            
            private function initSE(event:Event = null):void
            {
                var kc:KeyCommand = new KeyCommand(KeyCommand.KONAMI_COMMAND, stage);
                kc.addEventListener(Event.COMPLETE, function(event:Event):void
                {
                    se.play();
                    rotate.play();
                });
            }
            
            private function nextView():void
            {
                viewstack.selectedIndex++;
            }
            
            protected function viewstack_changeHandler(event:IndexChangedEvent):void
            {
                if(event.target.selectedIndex == 2)
                {
                    _urulab = new UruLabEdit(spe.width, spe.height, "http://kb4102.dip.jp/data/" + _modelURI, _color);
                    spe.addChild(_urulab);
                    modelViewer.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
                    about.enabled = false;
                }
            }
            
            protected function colorcontainer_clickHandler(event:MouseEvent):void
            {
                _color = uint(event.currentTarget.name);
                nextView();
            }
            
            private function onRollOver(event:MouseEvent):void
            {
                if(_urulab.mode == UruLabMode.VIEW)
                {
                    modelViewer.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
                }
                modelViewer.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
            }
            
            private function onMouseDown(event:MouseEvent):void
            {
                modelViewer.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
            }
            
            private function onMouseUp(event:MouseEvent):void
            {
                modelViewer.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
            }
            
            private function onRollOut(event:MouseEvent):void
            {
                cursorManager.removeAllCursors();
                modelViewer.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
                modelViewer.removeEventListener(MouseEvent.ROLL_OUT, onRollOut);
                _urulab.onMouseUp(event);
            }
            
            protected function drawView_creationCompleteHandler():void
            {
                _ucp = new UruLabColorPicker();
                cp.addChild(_ucp);
            }
            
            protected function paletteButton_clickHandler():void
            {
                _paletteArray.pop();
                _paletteArray.unshift(_ucp.color);
                paletteArray.source = _paletteArray;
                palette.selectedIndex = -1;
            }
            
            private function listReset():void
            {
                if(svgList)
                    svgList.selectedIndex = -1;
                if(bmpList)
                    bmpList.selectedIndex = -1;
            }
            
            private function onSvgListComplete(event:Event):void
            {
                var xml:XML = XML(event.target.data);
                var len:int = xml.file.length();
                for(var i:int = 0; i < len; ++i)
                {
                    var loader:URLLoader = new URLLoader();
                    loader.addEventListener(Event.COMPLETE, onSvgLoadComplete(xml.file[i].name, xml.file[i].creater));
                    loader.load(new URLRequest("http://kb4102.dip.jp/data/" + xml.file[i].url));
                }
            }
            
            private function onSvgLoadComplete(name:String, creater:String):Function
            {
                return function(e:Event):void
                {
                    var shapeData:FShapeSVG = new FShapeSVG(XML(e.target.data));
                    _svgStampArray.push(new SetData(name, creater, null, shapeData.toSprite()));
                }
            }
            
            private function onBmpListComplete(event:Event):void
            {
                var xml:XML = XML(event.target.data);
                var len:int = xml.file.length();
                for(var i:int = 0; i < len; i++)
                {
                    var loader:Loader = new Loader();
                    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBmpLoadComplete(xml.file[i].name, xml.file[i].creater));
                    loader.load(new URLRequest("http://kb4102.dip.jp/data/" + xml.file[i].url));
                }
            }
            
            private function onBmpLoadComplete(name:String, creater:String):Function
            {
                return function(e:Event):void
                {
                    _bmpStampArray.push(new SetData(name, creater, e.target.content.bitmapData));
                }
            }
            
            protected function penButton_clickHandler():void
            {
                drawView.selectedIndex = 1;
                tool2PopUp.height = 200;
                _urulab.mode = UruLabMode.PEN;
                mode.text = "筆1モード";
                listReset();
            }
            
            protected function newPenButton_clickHandler():void
            {
                drawView.selectedIndex = 1;
                tool2PopUp.height = 200;
                _urulab.mode = UruLabMode.PEN2;
                mode.text = "筆2モード";
                listReset();
            }
            
            protected function bmpButton_clickHandler():void
            {    
                drawView.selectedIndex = 2;
                tool2PopUp.height = 500;
                listReset();
            }
            
            protected function bmpList_changeHandler(event:IndexChangeEvent):void
            {
                _urulab.mode = UruLabMode.STAMP_BMP;
                mode.text = "スタンプ1モード";
                _urulab.stamp = { bmp: _bmpStampArray[event.target.selectedIndex].bmpd, svg: null };
            }
            
            protected function svgButton_clickHandler():void
            {
                drawView.selectedIndex = 3;
                tool2PopUp.height = 500;
                listReset();
            }
            
            protected function svgList_changeHandler(event:IndexChangeEvent):void
            {
                _urulab.mode = UruLabMode.STAMP_SVG;
                mode.text = "スタンプ2モード";
                _urulab.stamp = { bmp: null, svg: _svgStampArray[event.target.selectedIndex].sp };
            }
            
            protected function eraserButton_clickHandler():void
            {
                drawView.selectedIndex = 4;
                tool2PopUp.height = 200;
                _urulab.mode = UruLabMode.ERASER;
                mode.text = "消しゴムモード";
                listReset();
            }
            
            protected function materialButton_clickHandler():void
            {    
                drawView.selectedIndex = 5;
                tool2PopUp.height = 200;
                _urulab.mode = UruLabMode.MAT_PEN;
                mode.text = "卵殻";
                listReset();
            }
            
            protected function viewButton_clickHandler():void
            {
                _urulab.mode = UruLabMode.VIEW;
                mode.text = "視点移動モード";
                drawView.selectedIndex = 0;
                listReset();
            }
            
            private function messageClick():void
            {
                clickCount++;
                if(clickCount == 10)
                    try {
                        navigateToURL(new URLRequest("http://unlock360.hp2.jp/u.swf?v=12&l=http%3A//kb4102.dip.jp/urulab/image/10&m=MTAgdGltZXMgY2xpY2tlcg&x=png"), "_blank");
                    } catch (err:Error) {
                        trace(err);
                    }
            }
            
            protected function menubar_itemClickHandler(event:MenuEvent):void
            {
                var str:String = event.item.@action;
                switch(str)
                {
                    case "undo":
                        _urulab.undo();
                        break;
                    case "redo":
                        _urulab.redo();
                        break;
                    case "zoomin":
                        _urulab.zoomIn();
                        break;
                    case "zoomout":
                        _urulab.zoomOut();
                        break;
                    case "turnon":
                        _urulab.lighting = true;
                        break;
                    case "turnoff":
                        _urulab.lighting = false;
                        break;
                    case "view":
                        viewButton_clickHandler();
                        break;
                    case "pen1":
                        penButton_clickHandler();
                        break;
                    case "pen2":
                        newPenButton_clickHandler();
                        break;
                    case "bmp":
                        bmpButton_clickHandler();
                        break;
                    case "svg1":
                        svgButton_clickHandler();
                        break;
                    case "rankaku":
                        materialButton_clickHandler();
                        break;
                    case "eraser":
                        eraserButton_clickHandler();
                        break;
                    case "showtool":
                        showtool.play();
                        break;
                    case "showtool2":
                        showtool2.play();
                        break;
                    case "showcolor":
                        showcolor.play();
                        break;
                    case "showmove":
                        showmove.play();
                        break;
                    case "about":
                        PopUpManager.centerPopUp(PopUpManager.createPopUp(this, AboutUrulab, true))
                        break;
                    default:
                        break;
                }
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:Move id="cameraPopUpMove" target="{cameraPopUp}" yTo="610"/>
        <s:Move id="toolPopUpMove" target="{toolPopUp}" yTo="610"/>
        <s:Move id="tool2PopUpMove" target="{tool2PopUp}" yTo="610"/>
        <s:Move id="palettePopUpMove" target="{palettePopUp}" yTo="610"/>
        <s:Sequence id="showtool" target="{toolPopUp}">
            <s:Move xTo="10" yTo="160" duration="150"/>
            <mx:Glow color="#0000ff" blurXFrom="10" blurYFrom="10"/>
        </s:Sequence>
        <s:Sequence id="showtool2" target="{tool2PopUp}">
            <s:Move xTo="625" yTo="55" duration="150"/>
            <mx:Glow color="#0000ff" blurXFrom="10" blurYFrom="10"/>
        </s:Sequence>
        <s:Sequence id="showcolor" target="{palettePopUp}">
            <s:Move xTo="120" yTo="535" duration="150"/>
            <mx:Glow color="#0000ff" blurXFrom="10" blurYFrom="10"/>
        </s:Sequence>
        <s:Sequence id="showmove" target="{cameraPopUp}">
            <s:Move xTo="600" yTo="500" duration="150"/>
            <mx:Glow color="#0000ff" blurXFrom="10" blurYFrom="10"/>
        </s:Sequence>
        <s:Rotate3D id="rotate" target="{viewstack}" angleXFrom="0" angleXTo="360" duration="2000" autoCenterTransform="true" easer="{elastic}"/>
        <s:Elastic id="elastic"/>
    </fx:Declarations>
</s:Application>