學flex寫的第一個小程式

來源:互聯網
上載者:User
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="474" height="526" creationComplete="initApp();"><mx:Script>        <![CDATA[        import flash.media.Sound;                private var my_sound:Sound=new Sound();        private var my_sound1:Sound=new Sound();        var zmb:Array = new Array("A", "B", "C", "D", "E", "F", "G", "H",         "I", "J", "K", "L", "M", "N", "O", "P", "Q",         "R", "S", "T", "U", "V", "W", "X", "Y", "Z");        var fenshu:int = 0;        var b:Boolean = false;                private function initApp():void        {            // 最好把事件綁定到需要響應事件的組件上, 而不是 application           // 否則文字框中也會響應按鍵動作,            // 嘗試把 keyTest 改成 application 然後在文字框中輸入            //click="event.target.setFocus();"            //stage.focus = this;            panel.addEventListener(KeyboardEvent.KEY_UP, keyHandler);            my_sound.load(new URLRequest("bz.mp3"));            my_sound1.load(new URLRequest("ok.mp3"));        }                public function startGame():void {        start.visible = false;        close.visible = false;        gameName.visible = false;        panel.visible = true;        stage.focus = panel;        run();        }                public function reinit():void {        start.visible = true;        close.visible = true;        gameName.visible = true;        panel.visible = false;        }                private function closeIE():void {            var request:URLRequest = new URLRequest("javascript:window.close()");            navigateToURL(request,"_self");            }                        private function keyHandler(event:KeyboardEvent):void {            super.keyDownHandler(event);            trace(event.keyCode.toString() + ":" + moveTag.text.charCodeAt(0).toString());            if (event.keyCode.toString().localeCompare(moveTag.text.charCodeAt(0).toString()) == 0) {            fenshu++;            fen.text = "計分" + fenshu;            b = true;            moveEffect2.stop();            }                      switch (event.keyCode){                    /* case 27:                    reinit();                    break; */                    case 13:                    reinit();                    break;      }            }                        private function run():void {            fenshu = 0;            fen.text = "計分:0";            moveEffect2.target = moveTag;            moveEffect2.duration = suiji();            moveEffect2.play();            b = false;            }                        private function endEffectHandler():void {            if (b)             my_sound1.play();             else            my_sound.play();                        b = false;            var index:int = Math.round(Math.random()*26) - 1;            moveTag.visible = false;            moveEffect3.yFrom = 0;            moveEffect2.duration = suiji();            moveEffect2.play();            moveTag.text = zmb[index];            moveTag.visible = true;            }                        private function suiji():int {            return Math.round(Math.random()*1000) + 1000;            }        ]]>    </mx:Script><mx:Parallel id="moveEffect1"><mx:Move xFrom="0" duration="1000" />    </mx:Parallel>      <mx:Sequence id="moveEffect2" effectEnd="endEffectHandler();"><mx:Move id="moveEffect3" yFrom="0" yTo="480"/>    </mx:Sequence>  <mx:Button id="close" visible="true" x="375" y="493" label="結束" width="89" height="23" fontSize="12" click="closeIE();"/><mx:Button id="start" visible="true" x="375" y="462" label="開始" width="89" height="23" fontSize="12" click="startGame();"/><mx:Label id="gameName" visible="true" creationCompleteEffect="{moveEffect1}" text="打字遊戲" width="131" height="39" fontSize="24" textAlign="center" fontWeight="bold" fontFamily="Verdana" horizontalCenter="-8" verticalCenter="-234"/><mx:Canvas  id="panel" visible="false" width="100%" height="100%" click="event.target.setFocus();"><mx:Label id="moveTag" x="209" y="0" fontWeight="bold" text="A" fontSize="23" width="29" /><mx:Label id="fen" x="354" y="10" width="110" height="27" fontSize="19" /></mx:Canvas></mx:Application>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.