您的位置:首页 > 理论基础 > 计算机网络

做了个非常简单的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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐