flash on 2009-8-22
♥0 |
Line 46 |
Modified 2009-08-22 09:56:27 |
MIT License
archived:2017-03-20 13:30:37
ActionScript3 source code
/**
* Copyright matsu ( http://wonderfl.net/user/matsu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dzxE
*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Style>
.myTextInput {
font-size: 16;
}
.errorTip {
color: #ffffff;
fontSize: 12;
fontWeight: "none";
borderColor: #990000;
paddingBottom: 4;
paddingLeft: 4;
paddingRight: 10;
paddingTop: 4;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.ToolTip;
import mx.managers.ToolTipManager;
private var errorTip:ToolTip;
private var tempStr:String;
private function myTextInputChange(evt:Object):void
{
var byteArray:ByteArray = new ByteArray();
byteArray.writeMultiByte(myTextInput.text, "shift_jis");
var myTextInputLength:int = byteArray.length;
if ( myTextInputLength > 20 ) {
myTextInput.text = tempStr;
if ( errorTip == null ) {
// ターゲットの x および y 位置を使用して、エラーヒントの位置を設定します。
errorTip = ToolTipManager.createToolTip("半角は20文字、大文字は10文字まで入力できます。", evt.currentTarget.x + evt.currentTarget.width, evt.currentTarget.y, "errorTipRight") as ToolTip;
}
} else {
tempStr = myTextInput.text;
if ( errorTip != null ) {
ToolTipManager.destroyToolTip(errorTip);
errorTip = null;
}
}
}
]]>
</mx:Script>
<mx:Text text="入力制限チェック"/>
<mx:TextInput id="myTextInput" styleName="myTextInput" width="200" height="26" change="myTextInputChange(event);" enter="myTextInputChange(event);"/>
</mx:Application>