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;
}
}
}
答案 0 :(得分:0)
是的,只需引用FocusEvent中提供的displayObject,我们就可以获得对悬停对象的引用。这允许您创建对正在悬停的对象的泛型引用,最终允许您将它放在任意数量的TextField上。
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 = "Your text value here";
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 == "")
{
textField.text = def1;
}
}