Flex Verification Code

Source: Internet
Author: User

// ========================================= Write a separate as class to obtain the verification code ================ ====

Package File
{
Public class flexcode
{
Public Function flexcode ()
{
}
/**
* Obtain the verification code based on the given number of digits.
* @ Param count number of verification Codes
* @ Return verification code string
*/
Public static function getcode (count: INT): String
{
VaR code: String = "";
VaR num: Number = 0;
For (var I: Int = 0; I <count; I ++)
{
Num = math. Floor (math. Random () * 10000 );
If (Num % 2 = 0)
{
// The number starts from 48 (the keycode of 48 is 0)
Code = code + String. fromcharcode (48 + (Num % 10 ));
}
Else
{// 65 uppercase letters, 96 lowercase letters
Code = code + String. fromcharcode (65 + (Num % 26 ));
}
}
Trace ("generate -->" + Code );
Return code;
}
}
}

 

// ====================== Mxml ==============================

<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" width = "939" layout = "absolute" Height = "517">

<Mx: style>
. Linkbutton {text-Decoration: underline; font-style: italic ;}
</MX: style>
<Mx: SCRIPT>
<! [CDATA [
Import file. flexcode;
// Display the verification code on the label
VaR code: String = "";
Public Function initcode (): void {
Code = flexcode. getcode (4 );
This. lblcode. Text = code;

// Draws the background color for the label.
Lblcode. Graphics. beginfill (0xff0000 );
Lblcode. Graphics. drawrect (0, 0, lblcode. Width, lblcode. Height );
Lblcode. Graphics. endfill ();
}
// Check the event and obtain the verification code again.
Private function refech (): void {
This. initcode ();
}
// Verify that user input is the same
Private function validate (): void {
If (txtcode. Text. touppercase () = Code ){
Alert. Show ("verified! ");
} Else {
Alert. Show ("Verification Failed ");
}
}
]>
</MX: SCRIPT>
<Mx: label x = "227" Y = "440" text = "label" width = "77" fontsize = "18" id = "lblcode" fontstyle = "italic"/>
<Mx: linkbutton x = "312" Y = "438" label = "cannot see clearly? "Color =" #031af8 "fontsize =" 18 "stylename =" linkbutton "creationcomplete =" initcode () "Click =" refech () "/>
<Mx: textinput x = "46" Y = "446" id = "txtcode"/>
<Mx: button x = "60" Y = "485" label = "Validate" width = "102" Click = "Validate ()"/>
</MX: Application>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.