ActionScript 3:尝试执行bitmap.draw()时出错;

时间:2014-01-03 17:09:26

标签: actionscript-3 flash bitmap

我正在使用flash AS3创建一个应用程序,它可以从movieClip(例如图像)创建一个snapshop并将数据发送到服务器(使用PHP接收数据)。因此,当在闪存上执行app时,RAW数据将被发送到服务器并创建我的文件映像。但是,当我将Flash Movie放在HTML Source上,并尝试在浏览器上执行时,电影已加载,但是将图像发送到服务器的操作未运行。

以下是我的代码:

var jpgSource:BitmapData = new BitmapData( 600, 600 );
jpgSource.draw(image); // <--- PROBLEM!!!

// encode it to jpeg and convert it to byte array
    var jpgEncoder:JPGEncoder = new JPGEncoder(85);
    var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);

    var request:URLRequest = new URLRequest("./post-image?facebookID="+user.facebook.id);
        request.requestHeaders.push(new URLRequestHeader("Content-type", "application/octet-stream"));
        request.method = URLRequestMethod.POST;
        request.data = jpgStream;


    var loader:URLLoader = new URLLoader();
        loader.dataFormat = URLLoaderDataFormat.TEXT;
        loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent){
            trace(e.status);
            ExternalInterface.call("console.log","Request Response Status: " + e.text);
            //ExternalInterface.call("console.log",e);
        }, false, 0, true);

        loader.addEventListener(Event.COMPLETE, function(e:Event){
            trace( new String(loader.data));
            ExternalInterface.call("console.log",new String(loader.data));
        }, false, 0, true);

        loader.load(request);

有谁知道可能会发生什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

我的猜测是,由于安全问题,闪存(在浏览器中)阻止了请求,尤其是在本地运行该文件时。尝试从运行PHP的同一台服务器上运行它,看看是否有帮助。您还可以进入计算机上的闪存设置,并将swf文件夹添加为受信任位置。 Flash IDE在浏览器中具有与闪存不同的沙箱限制。您也可以在firefox中尝试使用flashbug来查看是否可以显示您遇到的错误。希望这会有所帮助。