做了个非常简单的Flash验证码(附源代码) 转载于http://www.cordyblog.cn/?action=show&id=68

最近某个项目需要在flash登录,而验证码又不在服务器产生,就只需要一个flash里的随机验证码就行了。

于是就花了几分钟做了一个简单的随机验证码

效果还不错哦。

效果:

 

这个有33K之巨是因为偷懒,直接把组件拿来做展示的结果。。实际上微不足道的。。

主要代码
  1. var width=this._width;   
  2. var height=this._height;   
  3. var codebg = this.createEmptyMovieClip("codebg", 1);   
  4. this.createTextField("codeTxt", 2, 0, 0, width, height);   
  5. codeTxt.selectable=false;   
  6. codeTxt.autoSize="center";   
  7. codeTxt.html=true;   
  8. function getRandCode() {   
  9.     this.randCode = random(10)+""+random(10)+""+random(10)+""+random(10);   
  10.     codebg.clear();   
  11.     codeTxt.htmlText="";   
  12.     for(var i=0;i<50;i++){   
  13.         var x=random(width)+1;   
  14.         var y= random(height)+1;   
  15.         var ex=x+random(5)-2;   
  16.         var ey=y+random(5)-2;   
  17.         ex=ex<=0?1:ex>=width-1?width-2:ex;   
  18.         ey=ey<=0?1:ey>=height-1?height-2:ey;   
  19.         codebg.lineStyle(1,random(0xFFFFFF), 100);   
  20.         codebg.moveTo(x,y);   
  21.         codebg.lineTo(ex,ey);   
  22.     }   
  23.     for(var i =0;i<this.randCode.length;i++){   
  24.         if(random(2)){   
  25.             codeTxt.htmlText=codeTxt.htmlText+" ";   
  26.         }   
  27.         codeTxt.htmlText=codeTxt.htmlText+"<font size='18' color='#"+random(0xFFFFFF).toString(16)+"'><b>"+randCode.charAt(i)+"</b></font>"  
  28.     }   
  29. }   
  30. function checkCode(code){   
  31.     var match=String(code)==String(this.randCode);   
  32.     getRandCode();   
  33.     return match;   
  34. }   
  35. getRandCode();  
 下载地址: http://download.csdn.net/source/333152
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值