TextField, restrict, maxChars
forked from TextField_restrict_maxChars (diff: 43)
... @author ...
ActionScript3 source code
/**
* Copyright hacker_yk666qry ( http://wonderfl.net/user/hacker_yk666qry )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dGcX
*/
package
{
import flash.display.Sprite;
import flash.text.*;
import flash.events.*;
/**
* ...
* @author ...
*/
public class MyTextField extends Sprite {
private var tf:TextField;
private var tf2:TextField;
public function MyTextField() {
//入力テキストフィールド
tf = new TextField();
tf.type = TextFieldType.INPUT;
//入力可能な文字
tf.restrict = "_./0-9a-zA-Z村";
//入力可能な文字数
tf.maxChars = 20;
tf.x = 100;
tf.y = 100;
tf.width = 200;
tf.height = 24;
tf.border = true;
addChild(tf);
//カウントテキストフィールド
tf2 = new TextField();
tf2.x = 150;
tf2.y = 80;
tf2.width = 100;
tf2.height = 20;
tf2.autoSize = TextFieldAutoSize.LEFT;
//tf2.text = "入力可能な文字数はあと " + tf.maxChars.toString();
addChild(tf2);
tf.addEventListener(Event.ENTER_FRAME, changeHandler);
}
public function changeHandler(e:Event):void {
tf2.text = "入力可能な文字数はあと " + ( tf.maxChars - tf.length ).toString();
}
}
}
