为什么调度 Event.OPEN 而不是 IOErrorEvent.IO_ERROR?
为什么当 SWF 为在网络服务器上以及尝试加载无效 URL 时?
在本地运行 SWF 时,情况并不相同。
示例代码:
var CLS_UrlStream:URLStream = new URLStream(); // Initialize URLStream class instance.
CLS_UrlStream.addEventListener(Event.OPEN, FUN_StreamHandler); // Listen for successful connections.
CLS_UrlStream.addEventListener(IOErrorEvent.IO_ERROR, FUN_StreamHandler); // Listen for conenction errors.
CLS_UrlStream.load(new URLRequest("InvalidURL")); // Load file.
private function FUN_StreamHandler(FUN_PAR_Event:Event):void {
trace("EVENT TYPE: " + FUN_PAR_Event.type);
}
// Outputs: EVENT TYPE: open
Why does the load
method of the URLStream
class dispatch Event.OPEN
instead of IOErrorEvent.IO_ERROR
when the SWF is on a webserver and when trying to load an invalid URL?
The same doesn't apply when running the SWF locally.
Sample code:
var CLS_UrlStream:URLStream = new URLStream(); // Initialize URLStream class instance.
CLS_UrlStream.addEventListener(Event.OPEN, FUN_StreamHandler); // Listen for successful connections.
CLS_UrlStream.addEventListener(IOErrorEvent.IO_ERROR, FUN_StreamHandler); // Listen for conenction errors.
CLS_UrlStream.load(new URLRequest("InvalidURL")); // Load file.
private function FUN_StreamHandler(FUN_PAR_Event:Event):void {
trace("EVENT TYPE: " + FUN_PAR_Event.type);
}
// Outputs: EVENT TYPE: open
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Event.OPEN 在加载时被触发。所以永远都会被调用。
您可能需要 HTTPStatusEvent.HTTP_STATUS
Event.OPEN gets triggered on load. So will always be called.
You probably want HTTPStatusEvent.HTTP_STATUS
当SWF 在服务器上运行并请求不存在的资源时,服务器实际上会发送一条错误消息,该消息算作数据,因此不存在错误事件。这在本地并不适用,因为当请求不存在的文件时,没有 Web 服务器会响应错误。通过使用 Monster Debugger 进行实时跟踪发现了这一点。
When the SWF is running on the server and is requesting for a resource that doesn't exist, the server actually sends an error message which counts as data, thus there is no error event. The same didn't apply locally because there was no web server to respond with an error when a request for an nonexistent file is made. Discovered this by tracing live with the Monster Debugger.