我在网页中有一个Flash程序,试图将图片发布到网页上。当用户单击按钮时,Web浏览器开始导航到新页面,然后似乎挂起(我可以看到它通过从Firefox状态栏中的消息中读取传输数据开始转到页面)
这似乎也适用于调试版本,但不适用于导出版本。
Flash代码:
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("http://myurl.com/webcam_upload.php");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = encodedData;
try
{
navigateToURL(jpgURLRequest, "_Self");
}
catch(e:Error)
{
trace("error occured");
}
网页:
<object width='534' height='450' type='application/x-shockwave-flash' data='flash/photobooth.swf'>
<param name='allowNetworking' value='all'>
<param name='allowScriptAccess' value='always'>
<param name='movie' value='flash/photobooth.swf'>
<p>My stuff.</p>
</object>
答案 0 :(得分:1)
您不想“导航到网址”,因此navigateToURL不是您想要的。你想要做的是使用URLLoader调用网址,以及标题和编码图像......
// First create your URL variables — your encodedData
var variables:URLVariables = new URLVariables();
variables.image = encodedData;
// Secondly you need to create a URLRequest, passing the URLVariables and any header you want
var request:URLRequest = new URLRequest ("http://myurl.com/webcam_upload.php");
request.method = URLRequestMethod.POST;
request.data = variables;
// Finally you want to create the URLLoader, calling the URLRequest and listening to any listeners you want, ie COMPLETE...
var loader:URLLoader = new URLLoader();
loader.addEventListener (Event.COMPLETE, _onPostReturn, false, 0, true);
loader.load (request);
private function _onPostReturn(evt:Event):void {
// This will trace the response upon completion.
trace ( evt.target.data );
}