flex验证码生成

来源:互联网 发布:郑州java培训学校 编辑:程序博客网 时间:2024/04/29 08:04
<?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="initApp(event)">
    <fx:Library>
        <fx:Definition name="MYsq">
            <s:Group>
                <s:Rect width="100%" height="100%">
                    <s:stroke>
                        <s:SolidColorStroke color="red"/>
                    </s:stroke>
                </s:Rect>
            </s:Group>
        </fx:Definition>
    </fx:Library>
    <fx:Script>
        <![CDATA[
            import ascb.util.DateFormat;
            
            import mx.events.FlexEvent;
            import mx.formatters.DateFormatter;
            
            
            
            protected function initApp(event:FlexEvent):void
            {
                rail();
            }
            
            protected function rail():String
            {
//                var exp:Date = new Date(2013,5,30);
//                trace(DateFormat.DAYS[exp.month]);
//                var str:String = "\ti\tam\ta\ngirl.";
//                trace(str);
//                var str2:String = "djnfwojcvnwoejraok'Dkfawejfosdjfwenfljweiflnsjoeflsdkfnowejwsef";
//                var index:int = -1;
//                while((index = str2.indexOf("f",index+1))!=-1)
//                {
//                        trace("f在str2的第"+index);
//                }
//                var letters:Array = [14,45,10,1,125,4,87,2,1,57,25,5];
//                letters.sort(Array.NUMERIC);
//                trace(letters);
                //随机生成4位验证码
                var ran:Number;
                var num:Number;
                var code:String;
                var checkCode:String ="";
                for(var i:int=0;i<4;i++)
                {
                    ran = Math.random();
                    num = Math.round(ran*10000);
                    if(num%2==0)
                    {
                        //"0"的ascii码为48
                        code = String.fromCharCode(48+(num%10));
                    }
                    else
                    code = String.fromCharCode(65+(num%26));
                    checkCode+=code;
                }
                return checkCode;
            }
            
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    </fx:Declarations>
<!--    <fx:MYsq x="25" y="25" width="20" height="20"/>
    <fx:MYsq x="25" y="50" width="20" height="20"/>
    <fx:MYsq x="50" y="50" width="20" height="20"/>
    <fx:MYsq x="75" y="50" width="20" height="20"/>
    <s:Button id="btn" x="100" y="67" label="click me" click="btn.label='hello';"/>
    <mx:RichTextEditor x="340" y="91"/>-->
</s:Application>

原创粉丝点击