我目前正在flash中构建与项目的rss/xml feed有关的应用程序。我目前陷入困境,因为我一直遇到此错误:
错误打开URL'http://distilleryimage6.instagram.com/.jpg' 错误#2044:未经处理的ioerrorevent:。文字=错误#2036:加载永远不会完成。
我知道我的字符串picurl无法正常运行,但是我是否缺少使它起作用的东西?这是我的代码:
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
public class instagramFeed extends MovieClip {
//link to #rit xml loader
public var ritFileRequest = new URLRequest("http://instagram.com/tags/rit/feed/recent.rss");
public var ritXmlLoader = new URLLoader();
//link to #rochester xml loader
// same as above public variables
public function instagramFeed() {
// constructor code
trace("About to load...");
//Loads #rit hashtag xml data.
ritXmlLoader.load(ritFileRequest);
ritXmlLoader.addEventListener(Event.COMPLETE, displayRITInfo);
}
//focuses on data with #rit hashtag
public function displayRITInfo(e:Event):void{
var ritInstagramData:XML = new XML(ritXmlLoader.data);
var ritInfoList:XMLList = ritInstagramData.elements().item;
trace(ritInfoList);
//load the image
var ritPic:String = ritInfoList.*::condition.@code;
var picURL:String = "http://distilleryimage6.instagram.com/" + ritPic + ".jpg";
trace(picURL);
//show the image on the stage!
var ritImageRequest:URLRequest = new URLRequest(picURL);
var ritImageLoader:Loader = new Loader();
ritImageLoader.load(ritImageRequest);
addChild(ritImageLoader);
ritImageLoader.x=200;
ritImageLoader.y=100;
ritImageLoader.scaleX = 3;
ritImageLoader.scaleY = 3;
}
}
}
您的问题在于您的XML解析RSS feed。
我建议在E4X上刷。这是这样做的好资源:http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=4
我认为您的问题在于这一行:ritInfoList.*::condition.@code
尝试像So
一样修改此行var ritInfoList:XMLList = ritInstagramData..item; //this will get all the item nodes
然后这样的行:
var ritPic:String = ritInfoList[2]; //this grabs the value from the 3rd link node as a test
该值是我注意到的完全合格的URL,因此您不需要var picURL:String = "http://distilleryimage6.instagram.com/" + ritPic + ".jpg";
之后的行,因为ritPic
已经是完整的URL。
当您将请求发送到不存在的URL时,就会发生IO错误(至少在这种情况下)。如果将http://distilleryimage6.instagram.com/.jpg
扔进浏览器,则将获得一个错误页面。这是您的问题。将加载程序引导到适当的URL,您将无法获得IO错误
在您的代码中处理IO错误也适当。
var ritImageLoader:Loader = new Loader();
ritImageLoader.addEventListener( IOErrorEvent.IO_ERROR, this.ioErrorHandler );
ritImageLoader.load(ritImageRequest);
private function ioErrorHandler( e:IOErrorEvent = null ):void {
trace('An IO Error has occurred. You can use this function to display an error to the user or load a placeholder or whatever you wish');
}
这将防止由于该特定错误而导致应用程序崩溃。错误仍然存在,请记住这一点。您确实需要处理该错误。您的应用程序不再被派遣而不会死在您身上。