【问题标题】:retrieve variables from php and send to a js function via AS3从 php 中检索变量并通过 AS3 发送到 js 函数
【发布时间】:2013-02-13 00:07:53
【问题描述】:

谁能告诉我如何从我发布到的 php 文件中检索响应,然后将它们发送到 js 函数。

脚本中还有一个动画 gif 图像,它不显示动画。任何人都可以得到这个工作吗?

php 响应采用这种格式 variable1=blabla&varaibale2=blabla

function sendPixelData(e:MouseEvent):void {
      capture_mc.visible = false;
 send_mc.visible = false;

    txtReturn.htmlText="Uploading Image......<img src="loading.gif" /><br/> Please Wait!";
    var output:String = "";
    var col = "";
    for (var i:Number=0; i<bitmapData.height; i++) {
        for (var j:Number=0; j<bitmapData.width; j++) {
            col = bitmapData.getPixel(j,i).toString(16);
            // In some cases, the color will be truncated (e.g. "00FF00" becomes "FF00")  
            // so we are adding the missing zeros.  
            while (col.length<6) {
                col = "0" + col;
            }
            output += col;
        }
    }
    var request:URLRequest = new URLRequest("GetPixelData.php");
    var variables:URLVariables = new URLVariables();
    var myURLLoader:URLLoader = new URLLoader();
    variables.pixels=output;// all image pixel
    //trace("output" + output)
    variables.width=videoPreviewWidth;// video width
    variables.height=videoPreviewHeight;// video height
    request.data=variables;
    request.method=URLRequestMethod.POST;
    myURLLoader.addEventListener ("complete", onC);
    myURLLoader.load (request);
    function onC (e) {

         var result:String = 
      ExternalInterface.call( "redirectToURL(send variables here)" );
        trace ("save complete");
    }
}

【问题讨论】:

    标签: php actionscript-3 flash


    【解决方案1】:

    来自 PHP 的结果存储在 URLLoader 的 data 属性中,因此要检索它,请使用:

    function onC (e:Event) {
        var result:String = String(e.target.data);
        ...etc
    

    对于您问题的第 2 部分,Flash 不支持 gif 文件格式 - 您需要使用 jpg 或 png。

    顺便说一句,事件类型不要使用字符串 - 使用事件类型常量,例如:

    myURLLoader.addEventListener (Event.COMPLETE, onC);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      • 2017-04-26
      • 2014-02-07
      • 2018-01-18
      • 2019-06-09
      • 1970-01-01
      相关资源
      最近更新 更多