¶ÔAmfphpÒѾ­Á˽âºÜ¾ÃÁË£¬¾ÍÊÇûÓÐÇ×ÊÖÓùýÒ»´Î£¬½ñÌìͻȻÐÄѪÀ´³±£¬¶¯ÊÖʵ¼ùÁËÒ»·¬¡£

++++

Amfphp
      ÊÇPHPµÄRPC¹¤¾ß£¬Ëü¿ÉÒÔʹPHPÓëÏÂÊö¼¼ÊõÎÞ·ìͨÐÅ£º

      * Flash ºÍ Flex Remoting
      * JavaScript JSON ºÍ Ajax JSON
      * XML ºÍXML-RPC

      Ò»¡¢Ê²Ã´ÊÇRPC?

      Ô¶¶Ë³ÌÐòµ÷ÓÃ(RPC£¬ Remote Procedure Call) ÊÇÒ»ÖÖ¿Í»§¶ËÓë·þÎñÆ÷¶Ë½»»»Êý¾Ý·½Ê½¡£ÎÒÃÇ¿ÉÒÔµ÷Óñ¾µØ¶ÔÏó´ø¶Ô¸÷ÖÖ²ÎÊý·½·¨£¬ÉèÖûص÷²¢½ÓÊܵ÷Óýá¹û¡£ÎÒÃDz»ÓùØÐÄ·¢ËͺͽÓÊÕÊý¾ÝµÄʵÏÖϸ½Ú¡£ÊµÏÖϸ½Úͨ³£ÊdzéÏóµÄ£¬ ¾ÍÏñÎÒÃÇÔÚµ÷Óñ¾µØ·½·¨Ò»Ñù.

      ¶þ¡¢¹¤×÷Ô­Àí

      ¿Í»§¶Ë£¨Flash£©Óë·þÎñÆ÷¶Ë£¨php£©, ʹÓÃÏàͬµÄ·½Ê½ÃèÊö·½·¨µ÷Óú͸´ÔÓÊý¾Ý¡£¿Í»§¶ËÐòÁл¯ÇëÇó²¢½«Ëü·¢Ë͵½Íø¹ØAmfphp¡£AmfphpÔÙÖ´ÐУº

          * ·´ÐòÁл¯ÇëÇó
          * ÕÒµ½ÏàÓ¦µÄÔ¶³Ì·þÎñÀà
          * ʵÀý»¯Àà
          * Ö´Ðа²È«¼ì²é
          * £¨Ê¹ÓÃÖ¸¶¨²ÎÊý£©µ÷Ó÷þÎñÆ÷¶Ë·½·¨
          * ÐòÁл¯·µ»ØµÄÊý¾Ý

      Amfphp ¿ÉÒÔÕýÈ·µØÐòÁл¯¡¢·´ÐòÁл¯¸´ÔÓÀàÐÍÊý¾Ý¡£³ýÁ˶ÔÏóºÍÊý×飬Ëü»¹Ö§³Öresources Êý¾ÝÁ¬½Ó×ÊÔ´£¬Õâ¾ÍÒâζ×ÅÎÒÃÇ¿ÉÒÔͨ¹ýµ÷ÓÃÔ¶³Ì·½·¨¼òµ¥·µ»Ømysql_query£¬amfphp »á´¦ÀíÕâÒ»ÇС£ Èç¹ûƽ̨֧³Ö (Ä¿Ç°À´Ëµ£¬Flash Remoting ºÍFlex Remoting), phpamf»¹¿ÉÒÔ´¦ÀíÑ­»·ÒýÓúÍ×Ô¶¨ÒåÊý¾Ý¡£ËüÒ²Ö§³Ö¼òµ¥µÄÔ¶³Ìµ÷ÊÔ¡£»¹ÓÐamfphp ¸½´øÒ»¸ö·þÎñä¯ÀÀÆ÷£¬Ëü¿ÉÒÔÔÚ´´½¨¿Í»§¶Ë´úÂëÇ°²âÊÔÔ¶³Ì·þÎñ¡£amfphp 1.0.1»¹Ìí¼ÓÁËÄ£°å£¬¿ÉÒÔ×Ô¶¯Éú³É¿Í»§¶Ë´úÂë¡£Amfphp 1.9 beta¸üÊÇÐÂÔöÁ˶ÔAMF3µÄÖ§³Ö¡£Ïê¼ûhttp://www.riafan.com/article.asp?id=31¡£

                ++++++

¡ôflash remotingÊÇʲô£¿

              Flash remotingÊÇÒ»ÖÖÁ¬½Óflash client Óë server¶ËµÄ¼¼Êõ£¬ËüµÄ¹¦ÓþÍÏñÊÇ web service, xml, loadVarsÒ»°ã£¬¿ÉÒÔÔÚÁ½ÕßÖ®¼ä½»»»×ÊÁÏ£¬´ïµ½¶¯Ì¬Öû»ÄÚÈݵÄÄ¿µØ¡£

              Flash remotingÌرðµÄµØ·½ÔÚÓÚËü’ñÓÃmacromedia¶À¼ÒµÄAMF(Action Message Format)£¬ÕâÊÇÒ»ÖÖ binary formatµÄ×ÊÁÏÐÍ̬£¬Í¸¹ý AMF over HTTPµÄ·½Ê½½«flash¶Ë×ÊÁϱàÂëºó´«»Øserver£¬server¶ËµÄremoting adaptor½ÓÊÕµ½×ÊÁϺóÔò»á½âÂë»ØÕýÈ·µÄnativeÎï¼þ£¬½»¸øÕýÈ·µÄ³Ìʽ´¦Àí¡£

              AMF³ýÁËÓÃÓÚFlash remotingÍ⣬Ҳ¹ã·ºµÄÓÃÓÚ Local Connection Óë Flash communication server£¬Ëü×î´óµÄÌØÉ«ÔÚÓÚ¿ÉÖ±½Ó½«flash native object£¬ÀýÈçObject, Array, Date, XML£¬´«»Øserver¶Ë£¬²¢ÇÒÔÚserver¶Ë×Ô¶¯½øÐÐתÒë³ÉÊʵ±µÄÎï¼þ£¬ÀýÈçflash µÄArray´«»ØPHPʱ¾Í»á×Ô¶¯×ª»»Îª Associative Array£»Õâ¸öÌØÉ«¶Ô¿ª·¢Õß×î´óµÄºÃ´¦ÔÚÓÚ²»ÐèÒªÔÙÈ˹¤´¦Àíserialization Óë deserializationµÄ·±Ñ}¹¤×÷£¬²»µ«¾«È·¶È¸ü¸ß£¬Í¬Ê±¿ª·¢Ò²¸üʡʱ¼ä¡£

              ÓÉÓÚAMFÊÇbinary format²¢ÇÒ±àÂëʱ¾­¹ý¸ß¶ÈѹËõ£¬Òò´Ë·Ç³£ÊʺÏÓÃÀ´´«µÝ´óÁ¿µÄ×ÊÁÏ£¬¸ù¾ÝflashorbÍøÕ¾µÄ²âÊÔ(Ö÷ÒªÕë¶Ôweb serviceÓëflash remoting)£¬µ±×ÊÁÏÁ¿Ô½´óʱ£¬flash remotingµÄ´«ÊäЧÄܾÍÔ½¸ß£¬Ô¶Ô¶³¬¹ýweb serviceµÄ±íÏÖ£¬Òò´ËͬÑùµÄµÀÀíÒ²¿ÉµÃÖªxml, loadVars, loadVariables µÈʹÓÃplaine text formatµÄ´«Ê䷽ʽ×ÔȻҲÎ޿ɱÈÄâ¡£

              ÖÁÓÚÔÚserver¶Ë£¬Ä¿Ç°macromedia¹Ù·½Ö§Ô®µÄƽ̨ÓÐÈýÖÖ£¬·Ö±ðÊÇ Java Coldfusion(µ«Êµ¼ÊÉÏColdfusionÓ¦¸ÃÖ»ËãÊÇjavaµÄsubset£¬ËüÊÇÒ»ÖÖ scripting tag library)Óë.NET£¬µ«ÓÉÓÚAMF¸ñʽÒѱ»Íæ¼Ò·´×éÒë³É¹¦£¬Òò´ËºÜ¿ìµÄ¾ÍÔÚOpen SourceȦ³öÏÖ¸÷ÖÖ¡¸Ãñ¼ä°æ¡¹µÄremotingÌæ´ú·½èñ£¬ÆäÖбȽÏÓÐÃûµÄÊÇ£º

              -AMFPHP: ÕâÊÇphp°æµÄremoting       http://amfphp.org
              -OPENAMF: java°æµÄremoting         http://openamf.org
              -Flap: Perl ÓëPython°æµÄremoting       http://simonf.com/amfpython/
              -FlashORB: ÉÌÒµ°æµÄremotingÌæ´ú·½èñ£¬Ä¿Ç°Ö§Ô®javaÓë.net       http://www.themidnightcoders.com/

              Ïà¹ØÔĶÁ£º
              Ê®¸ö’ñÓÃremotingµÄÀíÓÉ: http://www.macromedia.com/software/flashremoting/productinfo/upgrade/

¡ôamfphpÊÇƽô£¿

              ±¾ÎÄÖ÷Òª½éÉܵÄÊÇphpƽ̨ÉϵÄremoting·½èñ£¬Ò²¾ÍÊÇamfphp¡£

              Amfphp×îÔçÊÇÓÉJustin WatkinsËù·¢Æ𲢸ºÔð׫дµÚÒ»°æ´ó²¿·ÝµÄ³ÌʽÂ룬¾­¹ýÈýÄê·¢Õ¹ºóÈ¥ÄêÓÉPatrick Mineault½ÓÊÖ£¬²»µ«¸ÄÁ¼Á˴󲿷ݵijÌʽÂ룬ͬʱҲ²¹ÆëÁËÐí¶àÖØÒªµÄ¹¦ÄÜ£¬ÀýÈ籾ϵÁеڶþƪҪ½éÉÜµÄ pageable recordset¡£

              AmfphpÊÇÒ»¸öÍêÈ«ÓÉphpд³ÉµÄserver¶ËÄ£×飬×î´óµÄÌØÉ«ÔÚÓÚÍêÈ«²»Óð²×°£¬ÈκÎhosting Ö÷»úÖ»ÒªÄÜÅÜphp¾ÍÄÜÖ´ÐÐflash remoting£¬ÔÙ¼ÓÉÏphpÔ­±¾¾ÍÓйã´óµÄʹÓÃÕß»ù´¡£¬Òò´ËÒ»ÍƳöºóºÜ¿ì¾Í»ñµÃÍæ¼ÒÃǵĽÓÊÜ¡£

              Èç¹ûÄãÏëÒª²t½âamfphpµÄ×îз½Õ¹£¬¿ÉÇ°Íù amfphp wiki –http://amfphp.org/wiki/һ̽¾¿¾¹£¬Èç¹ûÄãÓÐʹÓÃÉϵÄÒÉÎÊ£¬×îºÃµÄ½â´ð¾ÍÔÚamfphp mailing list  http://sourceforge.net/mailarchive/forum.php?forum_id=24803»òÊÇ forum   http://sourceforge.net/forum/?group_id=72483¡£

¡ôÏÂÔØamfphp

              Ä¿Ç°amfphp×îаæΪ v1.0 milestone 2£¬¾ÝpatrickµÄ˵ÕâÓ¦¸ÃÊÇÕýʽ·¢±íÇ°×îºóÒ»¸öbeta°æ£¬ËùÒÔÎȶ¨ÐÔÓ¦¸ÃÏ൱²»´í²ÅÊÇ¡£

              ÏÂÔØλַ http://prdownloads.sourceforge.net/amfphp/amfphp-ms2-20050726.zip?download

¡ô°²×°amfphp

              µµèñ×¥»ØÀ´ºó½âѹËõ£¬Ó¦¸Ã»áµÃµ½ÏÂͼµÄ½á¹¹£º

              ÆäÖÐflashservices¾ÍÊÇamfphpµÄºËÐÄÄ£×飬ֻҪ½«ËüÉÏ´«µ½ÍøÒ³µÄ¸ùĿ¼Ï¼´¿É¡£±¾ÎÄÊÇÒÔwindows + apache 2ΪÀý£¬Òò´Ë·ÅÖÃλΪ£º

              E:\webroot\flashservices

              ÆäÖÐ webroot¼´ÊÇapacheÔ¤ÉèµÄÍøÒ³¸ùĿ¼£¬Èç¹ûÄãµÄλÖò»Í¬ÇëÊʵ±Ð޸ġ£
              ·ÅºÃ flashservicesºó»ù±¾ºËÐľÍÒÑÍê³É£¬µ«Õâ²»´ú±í¾Í¿ÉÒÔ¿ªÊ¼Ê¹Óã¬ÎÒÃÇ»¹ÒªÎªÃ¿¸öרèñ½¨Á¢×¨ÊôµÄ×ÊÁϼÐÀ´·ÅÖÃÆäËü±Ø±¸µÄµµèñ¡£

¡ôµÚÒ»¸ö³Ìʽ£ºhello world

              ÕâÀïÎÒÃÇÓÃÒ»¸öʵ¼ÊµÄhello world·¶ÀýÀ´Ê¾·¶ÈçºÎÈÃflash Óë php͸¹ýamfphp½øÐйµÍ¨¡£

              Ê×ÏÈÎÒÃÇÔڸղŵÄÍøÒ³¸ùĿ¼ÏÂ(htdocs)½¨Ò»¸öרèñ×ÊÁϼУ¬Ãû³ÆΪ hello£¬ÍêÕû·¾¶Îª£º
              E:\webroot\hello

              È»ºóÇëÏÂÔر¾Îĵķ¶Àýµµèñzipµµ£¬½«ÀïÃæµÄ¶«Î÷È«²¿½âѹËõµ½hello×ÊÁϼÐÄÚ£¬´Ëʱ×ÊÁϼеÄÄÚÈÝÓ¦¸ÃÈçÏÂͼ£º

¡ô Amfphp gatewayµÄÉ趨

              ½ÓÕßÎÒÃǾÍ×Ðϸ¿´¿´ÀïÃæÓÐЩʲô¶«Î÷£¬Ê×ÏÈÎÒÃÇÀ´¿´ gateway.php£¬³ÌʽÂëÈçÏ£º
              PHP:

ÎļþÃû³Æ£º../../amfphp/gateway.php
  1. <?php
  2.     include “/amfphp/Gateway.php”;
  3.     $gateway = new Gateway();
  4.     $gateway->setLooseMode(true);
  5.     $gateway->setCharsetHandler(“iconv”, “UTF-8”, “UTF-8”);
  6.     $gateway->setWebServiceHandler(‘php5’);
  7.     $gateway->setBaseClassPath(“services/”);
  8.     $gateway->service();
  9. ?>

              ÕâÀïÐÂÊÖ×î³£´íµÄµØ·½¾ÍÊǵÚÒ»ÐУ¬includeµÄÉ趨¡£Ò»°ãÓÉÓÚ flashservicesºËÐÄÄ£×鶼ÊÇ·ÅÖÃÓÚweb serverµÄ¸ùĿ¼£¬Òò´Ëÿ¸öרèñµÄ×Ó×ÊÁϼÐÖ»ÒªÓÃÏà¶Ô·¾¶ .. ¾Í¿ÉÒÔ´æÈ¡µ½¡£µ«Èç¹ûÄãµÄflashservices·¾¶²»Ò»Ñù£¬ÕâÀï¾ÍÒª×öÊʵ±µÄÐ޸ģ¬ÀýÈçÔÚÎÒʹÓõÄhostingÖ÷»úÉÏ(ʹÓÃlinuxϵͳ)£¬Õâ¸ö·¾¶¾Í¿ÉÄܱä³É£º

              /home/userrname/website.url/user/apache/htdoc/flashservices

              ×ÜÖ®ÕâÀïÇëСÐÄÈ·ÈÏ·¾¶ÎÞÎó¡£

              ½ÓÕßµÚ5ÐеÄÉ趨ҲºÜÖØÒª£¬ÕâÀïÖ÷ÒªÊÇÔÚÉ趨php¸ÃÓúÎÖÖÓïϵ´¦Àí×ÊÁÏ£¬ËüµÄ±ê×¼¸ñʽÈçÏ£º

              setCharsetHandler(string mode, string phpCharset, string sqlCharset)

              µÚÒ»¸ö²ÎÊýÊÇÉ趨ҪʹÓúÎÖÖ·½Ê½À´ÖØбàÂë´«ÊäµÄ×ÊÁÏ£¬Èç¹ûÊÇphp5µÄ»°Ôò¿ÉÒÔ·ÅʹÓÃiconv£¬ÕâÊÇÄÚ½¨µÄÄ£×é¡£

              µÚ¶þ¸ö²ÎÊýÊÇÉ趨ϵͳԤ¶¨µÄÎÄ×Ö±àÂ뷽ʽ£¬Èç¹ûÒªÓÃÖÐÎĵĻ°¾Í¸Ä³É utf-8¡£

              µÚÈý¸ö²ÎÊýÊÇÉ趨¸ÃÈçºÎ´¦Àísql query result£¬Ò²¾ÍÊÇrecordsetµÄÎÄ×Ö±àÂ룬ͬÑùµÄÒªÓÃÖÐÎÄÇëÉ趨³É utf-8¡£

              ±¾À´ÕâÀﻹÓеÚËĸö²ÎÊý£¬ÊÇÉ趨 wsCharset (web service charset)£¬µ«´Óms1°æ±¾¿ªÊ¼Õâ¸ö²ÎÊýÒѱ»Ô¤ÉèΪutf-8£¬½«À´²»ÂÛÊÇʹÓÃSoapClient»ò nusoap¶¼»á×Ô¶¯¶ÁÈ¡ phpCharsetµÄÉ趨ΪԤÉèÖµ¡£

              ËùÒÔ×ÜÖ®ÕÕ·¶ÀýÀïµÄÉ趨ֱ½ÓÌ×ÓþÍÒ»¶¨²»»á´í 😛

              ×îºó¿´Ò»ÏµÚ7ÐУ¬ÕâÀïÊÇÉ趨server¶ËµÄ³ÌʽλÖã¬Ò»°ãÒ²¾ÍÊÇbusiness logicµÄËùÔڵأ¬»òÊÇbusiness delegateµÄclassλÖÃ(Èç¹ûÄãÏ£Íû½«server¶ËµÄlogicƒ?Á¿Òþ²ØÆðÀ´Ö»Í¸¹ýµ¥Ò»¹ÜµÀ¹©flashºô½ÐµÄ»°£¬ÕâÀï¾ÍÊÇÏÂÊֵĺõط½)£¬Ô¤ÉèÖµÊÇserver£¬ÕâÒ²¾ÍÊÇΪºÎ½âѹËõ·¶Àýµµºó»á³öÏÖÒ»¸öͬÃû×ÊÁϼеÄÔ­Òò¡£

¡ôphp classµÄÄÚÈÝ

              ½ÓÕßÎÒÃÇ¿´Ò»ÏÂservice×ÊÁϼÐÄÚµÄHello.php£¬Õâ¸ö¾ÍÊÇserver¶ËµÄ³Ìʽ£¬ËüµÄµØλÏ൱ÓÚcoldfusion ÀïµÄcomponent(CFC)»òjavaÀïµÄjava bean¡£

              ËüµÄ³ÌʽÂëÈçÏ£º
              PHP:
   

ÎļþÃû³Æ£º../../amfphp\\services\\Hello.php
  1. <?
  2. class Hello
  3. {
  4.            function Hello()
  5.            {
  6.         $this->methodTable = array(
  7.             “sayHello” => array(
  8.                 “description” => “Return hello message to client”,
  9.                 “access”      => “remote”,
  10.                 “arguments”   => array(“”)
  11.                    ),
  12.                );
  13.            }
  14.            function sayHello($msg)
  15.            {
  16.                return “Amfphp welcomes you: ” . $msg . ” current time_” . time();
  17.            }
  18. }
  19. ?>

              Èç¹ûÄãÓÐ׫дphp classµÄ¾­Ñ飬Ӧ¸ÃÂíÉϻᷢÏÖÕâ¸öHello ¾ÍÊÇÒ»¸ö±ê×¼µÄphp classµµ£¬Í¸¹ýclass keywordÀ´Ðû¸æclassµÄÆôʼ£¬²¢ÇÒÔÚconstructorÀïÓÐÒ»¸ömethod tableÃèÊöÕû¸öclassÒª¹©Íâ½ç²Ù×÷µÄmethod¡£

              ×¢ÒâÕâ¸ömethod tableÀﻹÓÐÐí¶à¹Ø¼ü×Ö¿ÉÓã¬ÔÚδÀ´µÄ½ÌѧÎÄÕÂÀï»áÒÀÐò½éÉÜ¡£ÕâÀïÎÒÃÇÖ»Óõ½description, access, argumentsÈýÑù¡£ÆäÖÐaccessÒ»¶¨ÒªÉ趨³Éremote£¬Õâ¸ömethod²ÅÄÜΪÍâ½çËù´æÈ¡£¬²»È»¾Í»á³öÏÖ´íÎóѶϢ¡£

              µÚ17ÐпªÊ¼ÎÒÃÇдÁËÒ»¸ösayHello($msg) £¬Ëü»á½ÓÊÕÔ¶¶Ë´«À´µÄÒ»¸ö²ÎÊý$msg£¬È»ºóÎÒÃǽ«Õâ¸ö$msg¼ÓÁϺóÔÙ´«»ØÈ¥¡£¼ÓÁϵIJ¿·ÝÊÇ19ÐÐ×îºóµÄtime()£¬ÎÒÃǽ«Ä¿Ç°serverµÄʱ¼ä´«»Øflash¡£

¡ôflash¶Ë³Ìʽ

              ½ÓÕßÎÒÃÇ¿´Ò»ÏÂflash¶ËµÄ³Ìʽ¡£Ê×ÏÈÇë×¢ÒâÎÒÔÚtimelineµÄµÚ1¸ñÓÃincludeµÄ·½Ê½½«³ÌʽÂë¼Ó½øÈ¥£¬ÕâÑùÎҾͲ»ÓÃÔÚflash Àï¿ÉÁ¯µÄд³ÌʽÂ룬¶ø¿ÉÒÔÓà eclipse»òprimailscirptµÈ³¬Ç¿Î޵б༭Æ÷¿ìÀÖµÄд×÷£»ËùÒÔÄãÒªÕÒ³ÌʽÂëµÄ»°£¬Ö±½Ó´ò¿ªcode.asÕâ¸öµµèñ¼´¿É¡£

              Code.asµÄÄÚÈÝ£º

ÎļþÃû³Æ£º../../amf/code.as
  1. /*
  2. @author: jeremy@richtechmedia.com
  3. @website: http://ria.richtechmedia.com
  4. released under CC 2.5.
  5. */
  6. //remoting related classes
  7. import mx.remoting.Service;
  8. import mx.remoting.PendingCall;
  9. import mx.remoting.RecordSet;
  10. import mx.remoting.debug.NetDebug;
  11. import mx.rpc.RelayResponder;
  12. import mx.rpc.ResultEvent;
  13. import mx.rpc.FaultEvent;
  14. //start debugging so we can see debug info in NCD.
  15. NetDebug.initialize();
  16. //gateway settings
  17. var gateway:String = “http://localhost/amfphp/gateway.php”;
  18. respGeneral = new RelayResponder(this, “resultReceived”, “resultFailure”);
  19. _service = new Service(gateway, null, “Hello”, null, respGeneral);
  20. //callback when result was returned from server
  21. function resultReceived(re:ResultEvent):Void{
  22.     trace(“message from server > “ + re.result);
  23.     //php returns time in seconds, but flash Date class needs ms hence * 1000
  24.     var tmp = re.result.split(“_”)[1]*1000;
  25.     trace(“server time > “ + new Date(tmp));
  26. };
  27. //send message to server
  28. btnSend.clickHandler = function(){
  29.     var pc:PendingCall = _service.sayHello(inputText.text);
  30. }

      

              Ò»¿ªÊ¼ÎÒÃÇÏȽ«flash remotingÐèÒªµÄclass¶¼import½øÀ´£¬ÕâÀïҪעÒâµÄÊÇ£¬flash remotingÐèÒªÁíÍâÏÂÔØÓë°²×°£¬ÏÂÔصķ½Ê½ÓÐÁ½ÖÖ£º

              1¡¢ ÏÂÔØflash remoting components (v2)²¢×°Èëflash
              2¡¢ ÏÂÔØflash remoting sources²¢½âѹËõµ½ mxĿ¼Ï¡£Flash Remoting AS2 Classes http://download.macromedia.com/pub/flashremoting/mx2004/components/actionscript_2.0/flashremoting_comp_sourcecode.zip

              µÚÒ»ÖÖ·½Ê½±È½Ï¼òµ¥£¬Ö»Òª°²×°mxp¼´¿É½«remotingÔª¼þ×°Èëflash£¬ÈÕºóʹÓÃʱֻҪֱ½ÓÍÏ·ÅÕâ¸öÔª¼þµ½»­ÃæÉϼ´¿É¡£µÚ¶þÖÖ·½Ê½ÔòÊÇÖ±½ÓÈ¡»Øremoting classes²¢·ÅÈëflashÔ¤ÉèµÄmx·¾¶ÖУ¬ÕâÑù×öµÄºÃ´¦Óкܶ࣬ÀýÈç¿ÉÒÔÈý²»ÎåʱÐÞ¸ÄһЩµØ·½ÒÔ·ûºÏ×ÔÒѵÄÐèÇ󣬻òÊǽ«À´ÏëÓÃFAME¿ª·¢Ê±£¬Ò²¿ÉÒÔÈÃMTASCÕýÈ·µÄ±àÒë¡£

              ÕâÀïÎÒ¼ÙÉèÄãÒѾ­×°ºÃflash remoting Ôª¼þµÄ°æ±¾£¬ÔÚcomponentsÀïÒ²¿ÉÒÔ¿´µ½ flash remoting connectorÕâ¸öÔª¼þ¡£

              µÚ17ÐÐÎÒÃÇÆô¶¯NetDebugÕâ¸öÕì´í³Ìʽ£¬Ëü»á½«ËùÓеĴ«Êä½»Ò×ѶϢ¶¼ÏÔʾÔÚNetConnection Debugger(¿ªÆô·½Ê½ Window > Other Panel > NetConnection Debugger) À·½±ã³ý´í£¬ËüÊǹ¤³ÌʦµÄºÃÅóÓÑ£¬ÊµÔÚ²»ÄÜÒ»ÌìûÓÐËü¡­

              µÚ20ÐпªÊ¼ÎÒÃÇÉ趨Á˽«À´Á¬Ïߵķ¾¶£¬×¢ÒâÀïÃæµÄhello¾ÍÊǵ±³õÎÒÃÇÔÚhtdocsÀィµÄhello×ÊÁϼУ¬¶øgateway.php¾ÍÊÇÇ°Ò»½ÚËù½éÉܵÄphpµµèñ¡£

              µÚ21ÐÐÎÒÃÇÉ趨ÁËÒ»¸ögeneral responder£¬Ò²¾ÍÊÇÒ»¸öcatch-allµÄ»ØÓ¦Îï¼þ£¬Ö»Òªserver¶ËÓлش«Ñ¶Ï¢£¬¾ÍÓÉÕâÀïÉ趨µÄÁ½Ö§functionÈ¥³Ð½ÓÓë´¦Àí¡£µ±È» remoting´¦Àí»Ø´«Ñ¶Ï¢µÄ·½Ê½»¹ÓкܶàÖÖ£¬ÕâÀïÒòΪÊÇhello world¼¶µÄ·¶Àý¾ÍÏÈ°´Ï²»±í¡£

              µÚ22ÐÐÎÒÃǽ¨Á¢ÁËÒ»¸ö _service object£¬ÕâÊÇÄ£ÄâÔ¶¶ËclassµÄÒ»¸öÎï¼þ£¬ÇëÌرð×¢ÒâµÚÈý¸ö²ÎÊý Hello£¬ËüÊÇÖ¸ E:\webroot\amfphp\services\Hello.php Ò²¾ÍÊÇÇ°Ò»½Ú½éÉܹýµÄphp class¡£

              ¾­¹ýÕâÈýÐеÄÉ趨£¬ÎÒÃǾÍÍê³ÉflashÄÚµÄÁ¬ÏßÉ趨£¬½ÓÏÂÀ´¾Í¿ÉÒÔ¿ªÊ¼ºô½ÐÔ¶¶ËµÄmethod‡Ó£¡

              ÎÒÃÇÏÈÌøµ½µÚ33ÐУ¬ÕâÀïÎÒÃÇÉ趨ÁËÒ»¸ö°´Å¥£¬µ±°´ÏÂʱËü»áÖ´ÐÐ
              var pc:PendingCall = _service.sayHello(inputText.text);
              Ò²¾ÍÊÇ͸¹ýÏÈÇ°½¨Á¢µÄ _seriveÎï¼þÈ¥ºô½Ðserver¶ËµÄsayHello method, ²¢ÇÒ½«ÎÄ×Ö¿òÄÚÊäÈëµÄÄÚÈÝ´«»ØÈ¥¡£

              Õâ±ßÁíÍâҪעÒâµÄÊÇPendingCallµÄʹÓã¬ÓÉÓÚÎÒÃÇ¿ÉÄÜͬʱ¶Ôserver·¢Éú¶à¸örequest£¬µ«Ô¶¶ËÁ¬Ïß»ØÓ¦µÄËÙ¶Èͨ³£²»ÊǼ´Ê±µÄ£¬Òò´ËÐèÒªPendingCallÀ´¸ö±ðÖ¸¶¨Ã¿¸örequestµÄcallback function£¬½«À´Ò»¶ÑѶϢ´«»Øʱ²ÅÄÜÕýÈ·µÄ´¦Àí¡£

              ×îºóÎÒÃǻص½µÚ25ÐУ¬Õâ¸öfunction¾ÍÊǸºÔð½ÓÊÕ²¢´¦Àíserver»Ø´«×ÊÁϵĵط½¡£Ê×ÏÈÎÒÃÇÔÚµÚ26Ðн«server´«»ØµÄѶϢֱ½Ótrace³öÀ´£¬×¢ÒâÕâÀïҪʹÓà re.result²ÅÄÜ´æÈ¡µ½ÕýÈ·µÄѶϢ£¬ÕâÊdz£¼ûµÄ´íÎóÖ®Ò»¡£
              ½ÓÕßµÚ28¡¢29ÐÐÔòÊǽ«php´«»ØµÄdate stringת»»»ØflashµÄDate¸ñʽ£¬ÓÉÓÚphpÊÇÒÔ stringµÄ·½Ê½´¦Àíʱ¼ä¸ñʽ£¬Òò´ËÕâÀïÎÒÃǵÃÐÁ¿àµã×ÔÒѽ«ËüÔÙת»ØDate object¡£

              µ½ÕâÀï³ÌʽÂë¾Í¸æÒ»¸ö¶ÎÂ䣬ÎÒÃÇÀ´Ö´Ðп´¿´°É£¡

              ÕâÊdzÌʽִÐеĻ­Ã棬ÎÒÃÇÊäÈëһЩÎÄ×Öºó°´ÏÂsend.

              ÕâÊÇflash½«ÊäÈëÎÄ×Ö´«»ØphpµÄ»­Ã棬Çë×¢Òâ²ÎÊý²¿·ÝÕýÊÇÎÒÃÇÊäÈëµÄÎÄ×Ö

              ÕâÊÇphp»Ø´«Ñ¶Ï¢µÄ»­Ã棬ѶϢµÄβ¶ËÒѼÓÉÏϵͳµÄʱ¼ä

¡ôending

              Õâ¸öÀý×ÓÖÐÎÒÃǺܼòµ¥µÄÅÜÁËÒ»±éflash + amfphp + php µÄÖ´Ðз¶Àý£¬´Óflash´«Ò»¸öÎÄ×Ö´®»Øphp£¬²¢´Óphp´«Ò»¸ödateÎï¼þ»ØÀ´¡£

              ÔÚÕæʵèñÀýÖÐÃæ¶ÔµÄÇé¿öÍùÍù»á±ÈÕâ¸öÑ}ÔÓÐí¶à£¬ÀýÈçÖÁÉÙ»á¸údatabase»¥¶¯ÀÌ×ÊÁÏ»¥´«£¬»òÊǽøÐÐauthenticationµÄÈÏÔ^µÈ£¬µ«ÕâЩ¶¼ÊǺ󻰣¬ÔÚÖ®ºóµÄ·¶ÀýÖж¼»á½âÊÍ¡£

Õª³­–http://ria.richtechmedia.com/index.php?cat=25&paged=2

发表评论

电子邮件地址不会被公开。 必填项已用*标注