一句话限制Flash中所有的动态文本输入框只允许输入数字
刚开始的写法是:
function limitToNum(){
if (this.text != "-" && isNaN(this.text)) {
this.text = '';
}
}
a_txt.onChanged = limitToNum;
b_txt.onChanged = limitToNum;
c_txt.onChanged = limitToNum;
...
发现有点繁琐,突然想起'prototype':
TextField.prototype.onChanged = function() {
if (this.text != "-" && isNaN(this.text)) {
this.text = '';
}
};
这样就限制了Flash中所有的动态文本输入框。
由此还可以类推。比如:
MovieClip.prototype.onPress = startDrag;
MovieClip.prototype.onRelease = stopDrag;
MovieClip.prototype.onReleaseOutside = stopDrag;
这样Flash中所有的剪片剪辑都可以被拖拽了。
:) enjoy!
刚开始的写法是:
function limitToNum(){
if (this.text != "-" && isNaN(this.text)) {
this.text = '';
}
}
a_txt.onChanged = limitToNum;
b_txt.onChanged = limitToNum;
c_txt.onChanged = limitToNum;
...
发现有点繁琐,突然想起'prototype':
TextField.prototype.onChanged = function() {
if (this.text != "-" && isNaN(this.text)) {
this.text = '';
}
};
这样就限制了Flash中所有的动态文本输入框。
由此还可以类推。比如:
MovieClip.prototype.onPress = startDrag;
MovieClip.prototype.onRelease = stopDrag;
MovieClip.prototype.onReleaseOutside = stopDrag;
这样Flash中所有的剪片剪辑都可以被拖拽了。
:) enjoy!
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}