捕获类型错误 AS3 时出现问题
您好,我正在通过 XML 将图像和数据加载到 Flash 中。由于各种原因,某些数据丢失了图像或根本没有图像。当图像 URL 为 null 时,flash 返回消息 TypeError: Error #2007: Parameter url must be non-null。我一直在尝试使用 IO 错误事件捕获此错误,但我不确定这是否是执行此操作的正确方法,因为我似乎无法让它工作。这给我带来了一个问题,因为当我将项目添加到舞台时,数据与图像不匹配,一旦我能够捕获此错误,我想要做的就是将默认图像推入 _trackArray 中,我将然后用于将项目添加到舞台上。
private function callTracks(): void {
for (var i:Number = 0; i < _tracksTotal; i++){
var _trackpicUrl = _trackImage[i];
//trace(_trackImage[i]);
var _trackpicLoader = new Loader();
_trackpicLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, trackpicLoaded);
_trackpicLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
_trackpicLoader.load(new URLRequest(_trackpicUrl));
_trackpicLoader.name = i+1;
_trackArray.push(_trackpicLoader);
_containerMc.addChildAt(_trackpicLoader, _ringCounter);
}
}
private function loadError(e:IOErrorEvent): void {
trace("IO Error: " + e);
}
Hi I am loading images and data into flash via XML. Some bits of data are missing an image or just don't have one for various reasons. When the image URL is null flash returns the message TypeError: Error #2007: Parameter url must be non-null. I have been trying to catch this error using IO error event but I am unsure if this is the the correct method for doing this as I can't seem to get it working. This is causing a problem for me because when I add the items to the stage the data doesn't match the images and what I would like to do once I am able to capture this error is push a default image into the _trackArray which i will then use to add items to the stage.
private function callTracks(): void {
for (var i:Number = 0; i < _tracksTotal; i++){
var _trackpicUrl = _trackImage[i];
//trace(_trackImage[i]);
var _trackpicLoader = new Loader();
_trackpicLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, trackpicLoaded);
_trackpicLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
_trackpicLoader.load(new URLRequest(_trackpicUrl));
_trackpicLoader.name = i+1;
_trackArray.push(_trackpicLoader);
_containerMc.addChildAt(_trackpicLoader, _ringCounter);
}
}
private function loadError(e:IOErrorEvent): void {
trace("IO Error: " + e);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么为什么不在分配给
_trackpicUrl
时测试该值是否为 null 呢?So why not just test if the value is null when you assign to
_trackpicUrl
?您没有捕获 IOError 因为它永远不会到达 load()。上面来自 @shanethehat 的方法可以很好地填补空白,但为什么不首先研究一下为什么它是 null 呢?您是否动态生成 XML?
You aren't catching an IOError because it never gets to the load(). Method above from @shanethehat would work well to fill in the gaps, but why not look into why its null in the first place? Are you generating the XML dynamically?