MyCssStyle.css 参照flex组件的一些样式。
^_^
- <?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" minWidth="955" minHeight="600"
- creationComplete="init();">
- <fx:Style source="MyCssStyle.css"/>
- <s:layout>
- <s:BasicLayout/>
- </s:layout>
- <s:states>
- <s:State name="State1"/>
- <s:State name="index"/>
- </s:states>
- <fx:Declarations>
- <!-- 将非可视元素(例如服务、值对象)放在此处 -->
- </fx:Declarations>
- <fx:Script>
- <![CDATA[
- import mx.controls.Alert;
- private function generateCheckCode():String {
- var ran:Number;
- var number:Number;
- var code:String;
- var checkCode:String = "";
- for(var i:int=0; i<4; i++) {
- ran = Math.random();
- number = Math.round(ran * 10000);
- if(number % 2 == 0) {
- code = String.fromCharCode(48 + (number % 10));
- }
- else {
- code = String.fromCharCode(65 + (number % 26));
- }
- checkCode += code;
- }
- return checkCode;
- }
- private function init():void {
- lbl.text = generateCheckCode();
- }
- private function clickHandler(event:MouseEvent):void {
- if(username.text=="" || password.text=="" || txt.text=="") {
- Alert.show("请填入完整信息!");
- }
- else {
- if(txt.text != lbl.text) {
- Alert.show("验证码有误!");
- }
- else if(username.text=="gray" && password.text=="gray") {
- Alert.show("登录成功!");
- currentState = "index";
- }
- else {
- Alert.show("用户名或密码有误!");
- }
- }
- }
- private function clear(event:MouseEvent):void {
- username.text = "";
- password.text = "";
- txt.text = "";
- }
- ]]>
- </fx:Script>
- <s:Panel x="256" y="123" width="360" height="277" title="登录" fontSize="16" includeIn="State1">
- <s:Label x="10" y="45" text="用户名:" width="77" height="22"/>
- <s:TextInput x="129" y="41" id="username"/>
- <s:Label x="7" y="103" text="密 码:" width="81" height="25"/>
- <s:TextInput x="129" y="98" id="password"/>
- <s:Button x="177" y="201" label="登录" id="login" click="clickHandler(event);generateCheckCode();"/>
- <s:Button x="278" y="201" label="重置" id="reset" click="clear(event)"/>
- <s:Label x="7" y="156" text="验证码:" width="81" height="26"/>
- <s:Label x="96" y="156" width="136" height="26" id="lbl"/>
- <s:TextInput x="255" y="156" width="97" id="txt"/>
- </s:Panel>
- <s:Label includeIn="index" x="356" y="224" text="Welcome!!" width="155" height="37" fontSize="20"/>
- </s:Application>