• 【设为首页】
  • 【收藏闪客居】
当前位置:主页 > FLASH AS 编程 > AS进阶篇 > 文章内容
  • 给 Flash MX 增加新功能(4) TextField 类

  • 来源:闪客帝国 作者:闪客帝国整理 2006-06-26 【 】 TAG:

  今天提供给大家下面几个功能,全部是针对 TextField 的,想使用的话加到自己脚本里面去就可以了(浅蓝色框内的脚本可以直接拷贝)。

 鼠标点中文本框的时候,清除文本框内的文本。
 打字机效果。
 只允许输入数字。
 禁止某一个字符串。
  ××××××××××

  功能:鼠标点中文本框的时候,清除文本框内的文本。

  作者:brian

  代码:

Textfield.prototype.onSetFocus = function()
{
 if( this.firstrun == undefined )
 {
  this.defaulttext = this.text;
  this.firstrun = true;
 }
 if( this.text == this.defaulttext ) this.text = "";
};

Textfield.prototype.onKillFocus = function()
{
 if( this.firstrun == undefined )
 {
  this.defaulttext = this.text;
  this.firstrun = true;
 }
 if( this.text == "" ) this.text = this.defaulttext;
};  用法:

自动实现该功能。  ××××××××××

  功能:打字机效果。

  作者:gutknut

  代码:

TextField.prototype.typeWriter = function(str, ms) {
 var me = this;
 var i = 0;
 var itv = setInterval(function () {
  me.text = str.substring(0, i);
  i++;  
  if (i>str.length) {
   clearInterval(itv);
  }
  updateAfterEvent();
 }, ms);
};  用法:

//TEST
mystring = "Welcome to Flashempire, this is James speaking.";

_root.createTextField("mytext", 1, 20, 20, 200, 200);
mytext.multiline = true;
mytext.wordWrap = true;
// USAGE
mytext.typeWriter(mystring, 50);
  ××××××××××

  功能:只允许输入数字。

  作者:Borx

  代码:

TextField.prototype.toNumber = function(bool){
 if(bool){
  this.restrict = "0-9";
 } else {
  this.restrict = null;
 }
};
  用法:

myTextField.toNumber(true);
// 只能输入数字

myTextField.toNumber(false);
// 可以输入任何文字  ××××××××××

  功能:禁止某一个字符串。

  作者:不详

  代码:

TextField.prototype.restrictToString = function(str){
 var i, oldonchanged = this.onChanged;
 this.onChanged = function(){
  oldonchanged();
  for (i=0; i<this.text.length; i++){
   if (this.text.charAt(i) != str.charAt(i)){
    this.text = str.substr(0,i); break; }
  }
 }
}  用法:

AnyString.restrictToString("xxx");




上一篇:给 Flash MX 增加新功能(3) Array 类   下一篇:给 Flash MX 增加新功能(5) String 类
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)