Flash 联系表的问题

发布于 2024-07-16 05:23:32 字数 3138 浏览 3 评论 0原文

在Flash(AS3)中,我创建了一个联系表单,其中我使用了一个“提交按钮”,一个“重置按钮”,四个输入文本字段 “姓名、电子邮件、主题、消息”,实例名称为“contact_name、contact_email、contact_subject、contact_message”

我对 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);
}
}

谢谢 --瓦姆西

In Flash (AS3) Iam creating a contact form in that i have taken one " Submit Button" , one " Reset Button", four input text fields
" Name, Email, Subject, Message" with instance names " contact_name, contact_email, contact_subject, contact_message"

Iam very much confused about setFocus and killFocus.

In AS3, i have given

contact_name.text = "Name";
contact_email.text= "Email";
contact_subject.text = "Sub";
contact_message.text = "Message";

Now when i publish this file, bydefault the input text field shows with text
"Name, Email, Sub, Message"

Now my requirement is if i click on Name Field so the text "Name" should get disappear so that i can enter my name, after that i click on Email field
the text "Email" should get disappear at the same time i don't want to lose my Name which is entered in Name Field.

If i click in Subject text Field the text "Sub" should get disappear but not to lose the Name and Email data entered by me.

If i click in Message text Field the text "Message" should get disappear but i don't want to lose the data which was entered in remaining text fields.

Please see the action script below.
Please help me to find the solution.

Action Script :

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);
}
}

Thanks
--vamsi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笔绘流年 2024-07-23 05:23:32

假设您的 contact_name 是一个 Button,您可以添加一个事件侦听器,当用户单击此字段时,该事件侦听器会重置 text 属性。 就像是:

contact_name.addEventListener(
             MouseEvent.CLICK, 
             function(e:Event):void { 
                 contact_name.text = ''; 
             }
);

Assuming your contact_name is a Button you can add an event listener that resets the text property when a user clicks on this field. Something like:

contact_name.addEventListener(
             MouseEvent.CLICK, 
             function(e:Event):void { 
                 contact_name.text = ''; 
             }
);
谁人与我共长歌 2024-07-23 05:23:32

我会使用 focusIn 事件而不是 click,因为通过文本字段切换不会清空它们......
另外,当您从文本字段中将其留空时,它应该重新填充其标签文本......

var defaultText="Name";
addEventListener(FocusEvent.FOCUS_IN, function() {
   if(text==defaultText) {
      text="";
   }
}
addEventListener(FocusEvent.FOCUS_OUT, function() {
   if(text=="") {
      text=defaultText;
   }
}

I would use the focusIn event instead of click, since tabbing through your textfields wouldn't empty them...
Also, when you focusOut from the textfield leaving it empty, it should refill with its label text...

var defaultText="Name";
addEventListener(FocusEvent.FOCUS_IN, function() {
   if(text==defaultText) {
      text="";
   }
}
addEventListener(FocusEvent.FOCUS_OUT, function() {
   if(text=="") {
      text=defaultText;
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文