从php检索变量并通过AS3发送到js函数

时间:2013-02-13 00:07:54

标签: php actionscript-3 flash

任何人都可以告诉我如何从发布的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");
    }
}

1 个答案:

答案 0 :(得分:0)

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);