• 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

  • 相关阅读:
    分页
    ARC127C Binary Strings 思维 二进制 树
    ARC127A Leading 1s 数位DP
    【算法复习】背包问题 经典动态规划
    iOS15真机调试包下载
    Linux基础03 绝对路径/相对路径, 切换目录cd, 创建目录mkdir, 创建文件touch, 树状显示tree, 复制cp
    Jedis支持哨兵模式下认证
    19C ORA-00600: internal error code, arguments: [kkmmctbf:bad intcoln], [49]
    useMemo 和 useCallback 简单理解
    前端大屏页面布局经验
  • 原文地址:https://www.cnblogs.com/dt1991/p/7553744.html
Copyright © 2020-2023  润新知