【问题标题】:Flash navigateToURL hangs after navigation starts?导航开始后 Flash navigateToURL 挂起?
【发布时间】:2011-06-24 09:45:53
【问题描述】:

我在网页中有一个 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>

【问题讨论】:

    标签: flash flash-builder navigatetourl


    【解决方案1】:

    您不想“导航到 url”,因此 navigateToURL 不是您想要的。你想要做的是使用 URLLoader 调用一个 url,以及一个标题和编码的图像......

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

    【讨论】:

    • 感谢您的建议,但浏览器仍然开始传输数据,然后就坐在那里而不重新加载网页。
    • 跟踪是否输出任何内容? .php 应该返回一些东西到 flash,以便您重定向网页。
    • 不,因为我不明白它跟踪仅在调试模式下工作。 Flash 程序似乎可以在调试模式下工作,但不能在“已发布”版本中工作。
    • 它应该会进入一个新页面,就像您发布了一个 html 表单一样。
    • 我已经设法让它工作了:o)。项目文件似乎有些损坏。只需创建一个新项目(使用不同的名称),然后复制和粘贴代码似乎就可以了。
    猜你喜欢
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多