我在 Andreas 的帮助下完成了它。我还添加了更多代码来获取目标文本字段的默认文本值。当我专注时,这有助于我将目标字段的文本设置回默认值。谢谢“安德烈亚斯”。
import flash.events.FocusEvent;
import flash.text.TextField;
input1.addEventListener(FocusEvent.FOCUS_IN,inHand);
input1.addEventListener(FocusEvent.FOCUS_OUT,outHand);
//add all the other text input references like I did below...
input2.addEventListener(FocusEvent.FOCUS_IN, inHand);
input2.addEventListener(FocusEvent.FOCUS_OUT, outHand);
var def1:String = input1.text;
var def2:String = input2.text;
function inHand(evt:FocusEvent):void
{
var textField:TextField = TextField(evt.target);
textField.text = "";
}
function outHand(evt:FocusEvent):void
{
var textField:TextField = TextField(evt.target);
if(textField.text == "")
{
switch(textField.name)
{
case "input1":
textField.text = def1;
break;
case "input2":
textField.text = def2;
break;
default:
break;
}
}
}