做了个非常简单的Flash验证码(附源代码) 转载于http://www.cordyblog.cn/?action=show&id=68
2008-01-12 16:30
871 查看
Submitted by cordy on 2007, November 28, 2:39 PM. flash
最近某个项目需要在flash登录,而验证码又不在服务器产生,就只需要一个flash里的随机验证码就行了。
于是就花了几分钟做了一个简单的随机验证码。
效果还不错哦。
效果:
这个有33K之巨是因为偷懒,直接把组件拿来做展示的结果。。实际上微不足道的。。
主要代码
var width=this._width;
var height=this._height;
var codebg = this.createEmptyMovieClip("codebg", 1);
this.createTextField("codeTxt", 2, 0, 0, width, height);
codeTxt.selectable=false;
codeTxt.autoSize="center";
codeTxt.html=true;
function getRandCode() {
this.randCode = random(10)+""+random(10)+""+random(10)+""+random(10);
codebg.clear();
codeTxt.htmlText="";
for(var i=0;i<50;i++){
var x=random(width)+1;
var y= random(height)+1;
var ex=x+random(5)-2;
var ey=y+random(5)-2;
ex=ex<=0?1:ex>=width-1?width-2:ex;
ey=ey<=0?1:ey>=height-1?height-2:ey;
codebg.lineStyle(1,random(0xFFFFFF), 100);
codebg.moveTo(x,y);
codebg.lineTo(ex,ey);
}
for(var i =0;i<this.randCode.length;i++){
if(random(2)){
codeTxt.htmlText=codeTxt.htmlText+" ";
}
codeTxt.htmlText=codeTxt.htmlText+"<font size='18' color='#"+random(0xFFFFFF).toString(16)+"'><b>"+randCode.charAt(i)+"</b></font>"
}
}
function checkCode(code){
var match=String(code)==String(this.randCode);
getRandCode();
return match;
}
getRandCode();
下载地址:http://download.csdn.net/source/333152
最近某个项目需要在flash登录,而验证码又不在服务器产生,就只需要一个flash里的随机验证码就行了。
于是就花了几分钟做了一个简单的随机验证码。
效果还不错哦。
效果:
这个有33K之巨是因为偷懒,直接把组件拿来做展示的结果。。实际上微不足道的。。
主要代码
var width=this._width;
var height=this._height;
var codebg = this.createEmptyMovieClip("codebg", 1);
this.createTextField("codeTxt", 2, 0, 0, width, height);
codeTxt.selectable=false;
codeTxt.autoSize="center";
codeTxt.html=true;
function getRandCode() {
this.randCode = random(10)+""+random(10)+""+random(10)+""+random(10);
codebg.clear();
codeTxt.htmlText="";
for(var i=0;i<50;i++){
var x=random(width)+1;
var y= random(height)+1;
var ex=x+random(5)-2;
var ey=y+random(5)-2;
ex=ex<=0?1:ex>=width-1?width-2:ex;
ey=ey<=0?1:ey>=height-1?height-2:ey;
codebg.lineStyle(1,random(0xFFFFFF), 100);
codebg.moveTo(x,y);
codebg.lineTo(ex,ey);
}
for(var i =0;i<this.randCode.length;i++){
if(random(2)){
codeTxt.htmlText=codeTxt.htmlText+" ";
}
codeTxt.htmlText=codeTxt.htmlText+"<font size='18' color='#"+random(0xFFFFFF).toString(16)+"'><b>"+randCode.charAt(i)+"</b></font>"
}
}
function checkCode(code){
var match=String(code)==String(this.randCode);
getRandCode();
return match;
}
getRandCode();
下载地址:http://download.csdn.net/source/333152
相关文章推荐
- MFC 弹出窗口MessageBox的使用[转自http://www.bigasp.com.cn/blog/?action=show&id=51]
- 解决ASP(图像)上传漏洞的方法http://www.cnbruce.com/blog/showlog.asp?cat_id=26&log_id=942
- 踏入社会(http://www.sysinfo.cn/index.php?action=show&id=90)
- ASP.NET 缓存(七)--根据参数缓存页的版本http://www.opent.cn/?action=show&id=194
- ASP.NET 缓存(五)--使用文件依赖项缓存页输出http://www.opent.cn/?action=show&id=192
- HTML在线编辑器的原理(转载整理)http://www.cnbruce.com/blog/showlog.asp?log_id=1168
- 转:小结一下团队协作中的开源应用 转自:http://www.lingang.gd.cn/?action=show&id=329
- ASP.NET 缓存(四)--使用缓存键依赖项缓存页输出http://www.opent.cn/?action=show&id=191
- 因ARP欺骗网站源文件被注入了代码http://www.cnbruce.com/blog/showlog.asp?cat_id=32&log_id=1191
- IDEA快捷键(转载http://blogger.org.cn/blog/more.asp?name=lhwork&id=17063)
- 【转载】【权限控制】角色访问动态生成用户权限菜单树(转载: http://www.comprg.com.cn/post_show.asp?id=7873 )
- http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=10594&courseid=4
- http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=10102&courseid=0
- 不完全HTML在线编辑器收集 http://www.cnbruce.com/blog/showlog.asp?log_id=1021
- http://www.cppdev.cn/show.aspx?id=33&cid=6
- http://acm.hnu.cn/online/?action=problem&type=show&id=12817&courseid=267 7.19hnu/数据结构/数学 xxs.code
- VS .NET 2005中水晶报表的使用 http://www.tianyablog.com/blogger/post_show.asp?BlogID=116800&PostID=9731765
- INIT:Id "x" respawning too fast,disabled for 5 minutes解决思路 转自:http://www.xnlinux.cn/thread-1370-1-1.
- 常见病毒查杀与防御技巧(from:http://www.ccoo.cn/blog/blogshow.asp?aid=184498)
- Ubuntu 关机、重启、注销 命令 转自:http://www.blogguy.cn/show-628-1.html 作者:wayswang