Program E的Flash前端

来源:互联网 发布:晋中教育网网络教研 编辑:程序博客网 时间:2024/06/05 07:09
Program E是一个php的aiml解析器. (http://sourceforge.net/projects/programe/)
如果你对机器人聊天很感兴趣, 你肯定知道aiml, alicebox. 反正我是在03年就把这个东西用在了msn上(貌似是第一个).

无废话, 上代码:

php:

  1. /**
  2. * Include the guts of the program.
  3. */
  4. include "respond.php";
  5. $numselects=0;
  6. // Start the session or get the existing session.
  7. session_start();
  8. $myuniqueid=session_id();
  9. //echo 'botresponse='. $_POST['input'];
  10. //exit;
  11. // Here is where we get the reply. Make sure you fill in testbot with your bot's name
  12. if(isset($_POST['input'])){
  13.     //echo 'botresponse='. $_POST['input'];
  14.     $uid = isset($_POST['uid']) ? $_POST['uid'] : $myuniqueid;
  15.     $botresponse=replybotname($_POST['input'], $uid"ChinaBabel Bot No. 1");
  16.     echo 'botresponse=' . $botresponse->response;
  17.     echo '&myuniqueid=' . $uid;
  18. }
  19. // Print the results.
  20. //print "&bot_name=Test Agent/n";
  21. //print $botresponse->response;
  22. //print "&textLoaded=1";

Flash as2:

  1. var username;
  2. var keyListener:Object = new Object();
  3. keyListener.onKeyDown = function() {
  4.     // compare return value of getCode() to constant
  5.     if (Key.getCode() == Key.ENTER) {
  6.         _root.askBot(_root.ask.text);
  7.         _root.ask.text = "";
  8.     } 
  9.     else if(Key.getCode()==Key.ESCAPE){
  10.        //clear
  11.        _root.ask.text = "";
  12.     }
  13. };
  14. Key.addListener(keyListener);
  15. var myuniqueid:String = "";
  16. function askBot(ques:String):Void{
  17.     if(ques == ''){
  18.         return;
  19.     }
  20.     _root.answer.htmlText = "......";
  21.     
  22.     var botResponse:LoadVars = new LoadVars();
  23.     
  24.     var result_lv:LoadVars = new LoadVars();
  25.     result_lv.onLoad = function(success:Boolean) {
  26.         if (success) {
  27.             _root.append("机器人", result_lv.botresponse);
  28.             //_root.answer.text = result_lv.botresponse;
  29.             _root.myuniqueid = result_lv.myuniqueid;
  30.         } else {
  31.             _root.answer.text = "Error connecting to server.";
  32.         }
  33.     };
  34.     if(_root.myuniqueid != ""){
  35.         botResponse.uid = _root.myuniqueid;
  36.     }
  37.     botResponse.input = ques;
  38.     botResponse.sendAndLoad("http://www.xxx.com/bot/src/flash.php", result_lv, "POST");
  39. }
  40. function append(user, txt){
  41.     var tt = user + ' says: <span>' + txt + "</span>";
  42.     _root.answer.htmlText = tt;
  43. }
  44. askBot("I am "+username);





原创粉丝点击