当前位置: 首页 > 工具软件 > AMFPHP > 使用案例 >

AS3访问AMFPHP

吴城
2023-12-01

package {  
    import flash.display.Sprite;  
    import flash.net.NetConnection;  
    import flash.net.Responder;  
    import flash.text.TextField;  
    import flash.text.TextFormat;  
    public class amfphp extends Sprite{  
        public var connection:NetConnection;  
        public function amfphp(){  
            var textstr:String ='';  
            connection = new NetConnection();  
            connection.connect("http://localhost/amfphp/gateway.php");  
            var responder:Responder = new Responder(onResult);
            var responderSet:Responder = new Responder(onResultSet, onFault);
  
            connection.call("Welcome.sayHello",responderSet);
            connection.call("UserAction.getUsers",responder,"丁乐乐");  
            var txtformat:TextFormat = new TextFormat();  
            txtformat.font = "黑体";   
            var txt:TextField = new TextField();  
            txt.defaultTextFormat = txtformat;  
            txt.x = 50;  
            txt.y = 10 ;  
            txt.width = 400;  
            txt.height = 300;  
            txt.background = true;  
            txt.alwaysShowSelection = true;  
            //txt.selectable = false;  
            addChild(txt);    
            function onResult(result:Object):void{  
               
                for(var i:uint=0;i<result["serverInfo"]["totalCount"];i++){  
                    var dbdata:Array = new Array();  
                    dbdata = result["serverInfo"]["initialData"][i];  
                    textstr += "作者:"+dbdata[1]+"/n"+dbdata[2]+"/n";  
                    textstr += ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>/n";  
                }  
            txt.text = textstr;
            trace(result);  
            }
            function onResultSet(result:Object):void {
          
    trace( String(result));
    //txt.text=String(result);
   } 
   function onFault(fault:Object):void {
         
    trace(fault);
    
}

        }     
    }  
}

 类似资料: