·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3与php程序结合实现发送邮件的功能

时间:2014-03-18 14:20cuplayer.com
[AS3]as3与php程序结合实现发送邮件的功能,AS3与PHP,as3与php交互,as3发邮件

[AS3]as3与php程序结合实现发送邮件的功能,首先在属性中绑定 Main 类

  1. package 
  2.     import flash.display.*; 
  3.     import flash.events.*; 
  4.     import flash.text.*; 
  5.     import flash.net.*; 
  6.      
  7.     public class Main extends MovieClip 
  8.     { 
  9.         public function Main() 
  10.         { 
  11.             addEventListener(Event.ADDED_TO_STAGE,init); 
  12.         } 
  13.          
  14.         private function init(evt:Event):void 
  15.         { 
  16.             removeEventListener(Event.ADDED_TO_STAGE,init); 
  17.              
  18.             trace("My Document Class has been created correctly"); 
  19.              
  20.             form_mc.send_btn.addEventListener(MouseEvent.MOUSE_DOWN,checkFields); 
  21.         } 
  22.          
  23.         private function checkFields(evt:MouseEvent):void 
  24.         { 
  25.             if(form_mc.name_txt.text!=""&&form_mc.email_txt.text!=""&&form_mc.message_txt.text!="") 
  26.                 sendMessage(); 
  27.         } 
  28.          
  29.         private function sendMessage():void 
  30.         { 
  31.             var variables:URLVariables=new URLVariables(); 
  32.             variables.name=form_mc.name_txt.text; 
  33.             variables.email=form_mc.email_txt.text; 
  34.             variables.message=form_mc.message_txt.text; 
  35.              
  36.             var request:URLRequest=new URLRequest(); 
  37.             request.url='email.php'
  38.             request.method=URLRequestMethod.POST; 
  39.             request.data=variables
  40.              
  41.             var loader:URLLoader=new URLLoader(); 
  42.             loader.dataFormat=URLLoaderDataFormat.VARIABLES; 
  43.             loader.addEventListener(Event.COMPLETE,messageSent); 
  44.             try  
  45.             { 
  46.                 form_mc.status_txt.text = 'waiting...'
  47.                 loader.load(request); 
  48.             }  
  49.             catch (error:Error)  
  50.             { 
  51.                 form_mc.status_txt.text = 'Unable to load requested document.'
  52.             } 
  53.         } 
  54.          
  55.         private function messageSent(evt:Event):void 
  56.         { 
  57.             var loader:URLLoader=URLLoader(evt.target); 
  58.             var vars:URLVariables=new URLVariables(loader.data); 
  59.              
  60.             if(vars.answer=="ok"){ 
  61.                 form_mc.name_txt.text = ""
  62.                 form_mc.email_txt.text = ""
  63.                 form_mc.message_txt.text = ""
  64.                 form_mc.status_txt.text = "CuPlayer.com提示您:邮件发送成功!"
  65.             }else{ 
  66.                 form_mc.status_txt.text = "CuPlayer.com提示您:发送出错!"
  67.             } 
  68.         } 
  69.     } 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器