2006/06/12 | 一句话限制Flash中所有的动态文本输入框只允许输入数字
类别(Flash学习) | 评论(1) | 阅读(123) | 发表于 21:04
一句话限制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!
0

评论Comments