• as3与php交互


    (1)直接读取

    php:
    <?
    $state="开始接收";
    $var1="收到";
    echo "state=".$state."&var1=".$var1;
    ?>
    

     

    as:
    //btn是个按钮 txt是动态文本,在flash里面直接创建就OK
    btn.addEventListener(MouseEvent.CLICK,loadMss);
    txt.text="loading...";
    function loadMss(e:MouseEvent):void
    {
           var urlLoader:URLLoader=new URLLoader();
           urlLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
           urlLoader.load(new URLRequest("http://localhost/as3/admin.php"));//这里就是php文件的地址
           urlLoader.addEventListener(Event.COMPLETE,completeFun);
    }
    function completeFun(e:Event):void
    {
           var loadData:URLVariables=URLVariables((e.currentTarget as URLLoader).data);
           txt.text="正在:"+loadData.state+"
    ";
           txt.text+="接收情况:"+loadData.var1;
    }
    

    (2)读取PHP生成的xml

    php:
    <?
    //这里只是简单的echo出来了
    echo "<?xml version="1.0" encoding="utf-8"?>";
    echo "<pics>";
    echo "<p1>1.jpg</p1>";
    echo "<p2>2.jpg</p2>";
    echo "</pics>";
    ?>
    

      

    as:
    //btn是个按钮 txt是动态文本,在flash里面直接创建就OK
    btn.addEventListener(MouseEvent.CLICK,loadMss);
    function loadMss(e:MouseEvent):void
    {
           var urlLoader:URLLoader=new URLLoader();
           xmlLoader.load(new URLRequest("http://localhost/as3/xml.php"));//这里就是php文件的地址
           xmlLoader.addEventListener(Event.COMPLETE,completeFun);
    }
    function completeFun(e:Event):void
    {
           var loadData:XML=XML((e.currentTarget as URLLoader).data);
           txt.text=loadData.toString();
    }
    

      

    (3)通过GET传出参数

    //btn是个按钮 txt是动态文本,在flash里面直接创建就OK
    System.useCodePage=true;
    btn.addEventListener(MouseEvent.CLICK,loadMss);
    function loadMss(e:MouseEvent):void
    {
           var getLoader:URLLoader=new URLLoader();
          var request:URLRequest=new URLRequest();
           request.url="http://enatool.com/something.php";//这里是接收参数的地址
           request.method=URLRequestMethod.GET;//传出方法
           request.data="s=1";//传出具体的信息
           getLoader.load(request);
           getLoader.addEventListener(Event.COMPLETE,completeFun);
    }
    function completeFun(e:Event):void
    {
        txt.text=(e.currentTarget as URLLoader).data;
    }
    

      

    (4)通过POST传参

    //btn是个按钮 txt是动态文本,在flash里面直接创建就OK
    System.useCodePage=true;
    btn.addEventListener(MouseEvent.CLICK,loadMss);
    function loadMss(e:MouseEvent):void
    {
           var postLoader:URLLoader=new URLLoader();
           var request:URLRequest=new URLRequest();
          var vars:URLVariables=new URLVariables();
           vars.s1="flash";
           vars.s2="flex";
           request.url="http://enatool.com/something.php";
           request.method=URLRequestMethod.POST;
          request.data=vars;//这里的data可以是一个Object,或者Array
           postLoader.load(request);
           postLoader.addEventListener(Event.COMPLETE,completeFun);
    }
    function completeFun(e:Event):void
    {
        txt.text=(e.currentTarget as URLLoader).data;
    }
    

    转:http://blog.csdn.net/cceevv/article/details/7765413

  • 相关阅读:
    jquery easyui-datagrid手动增加删除重置行
    jsp中一行多条数据情况
    JQuery操作下拉框
    解决juqery easyui combobox只能选择问题
    oracle中WMSYS.WM_CONCAT函数的版本差异
    oracle wm_concat(column)函数的使用
    Javascript九大排序算法详解
    C#和VB新版本的最新特性列表
    Oracle中如何区别用户和模式
    远程控制数据库实用SQL重启功能
  • 原文地址:https://www.cnblogs.com/dt1991/p/7553744.html
Copyright © 2020-2023  润新知