在 Flash (AS3) 中,我创建了一个联系表单,其中我采用了一个“提交按钮”、一个“重置按钮”、四个输入文本字段“名称、电子邮件、主题、消息”,实例名称为“contact_name、contact_email、contact_subject、联系信息”
我对 setFocus 和 killFocus 感到非常困惑。
在 AS3 中,我给出了
contact_name.text = "Name";
contact_email.text= "Email";
contact_subject.text = "Sub";
contact_message.text = "Message";
现在,当我发布此文件时,默认情况下输入文本字段显示文本“名称、电子邮件、子、消息”
现在我的要求是,如果我单击名称字段,那么文本“名称”应该消失,以便我可以输入我的姓名,然后我单击电子邮件字段,文本“电子邮件”应该同时消失,我没有想丢失在名称字段中输入的我的姓名。
如果我单击主题文本字段,文本“Sub”应该会消失,但不会丢失我输入的名称和电子邮件数据。
如果我单击消息文本字段,文本“消息”应该会消失,但我不想丢失在剩余文本字段中输入的数据。
请参阅下面的操作脚本。请帮助我找到解决方案。
动作脚本:
contact_name.text ="Name";
contact_email.text ="Email";
contact_subject.text = "Sub";
contact_message.text ="Message";
message_status.text = "";
send_button.addEventListener(MouseEvent.CLICK, submit);
reset_button.addEventListener(MouseEvent.CLICK, reset);
var timer:Timer;
var var_load:URLLoader = new URLLoader;
var URL_request:URLRequest = new URLRequest( "send_email.php" );
URL_request.method = URLRequestMethod.POST;
function submit(e:MouseEvent):void
{
if( contact_name.text == "Name" || contact_email.text == "Email" ||
contact_subject.text == "Sub" || contact_message.text == "Message" )
{
message_status.text = "Please fill up all text fields.";
}
else if( !validate_email(contact_email.text) )
{
message_status.text = "Please enter the valid email address.";
}
else
{
message_status.text = "sending...";
var email_data:String = "name=" + contact_name.text
+ "&email=" + contact_email.text
+ "&subject=" + contact_subject.text
+ "&message=" + contact_message.text;
var URL_vars:URLVariables = new URLVariables(email_data);
URL_vars.dataFormat = URLLoaderDataFormat.TEXT;
URL_request.data = URL_vars;
var_load.load( URL_request );
var_load.addEventListener(Event.COMPLETE, receive_response );
}
}
function reset(e:MouseEvent):void
{
contact_name.text ="Name";
contact_email.text ="Email";
contact_subject.text = "Sub";
contact_message.text ="Message";
message_status.text = "";
}
function validate_email(s:String):Boolean
{
var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var r:Object = p.exec(s);
if( r == null )
{
return false;
}
return true;
}
function receive_response(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
var email_status = new URLVariables(loader.data).success;
if( email_status == "yes" )
{
message_status.text = "Success! Your message was sent.";
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, on_timer);
timer.start();
}
else
{
message_status.text = "Failed! Your message cannot sent.";
}
}
function on_timer(te:TimerEvent):void
{
if( timer.currentCount >= 10 )
{
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = "";
timer.removeEventListener(TimerEvent.TIMER, on_timer);
}
}
谢谢--vamsi