如何使用as3缓存图像?
这是我在 StackOverFlow 上发表的第一篇文章,我向您带来了一个困扰我的开发团队的问题。
我们在一个项目中,使用独立的 FlashPlayer 作为新闻显示器。 新闻提要是从 ASP.Net 请求返回的动态 XML,并在 Windows XP 上运行。
问题是: - 显示器在公交车屏幕上运行,有时互联网连接失败,但我们仍然需要继续显示已下载的新闻中的图像。当我们手动将字符串放在 URLRequest 上时,它就会起作用。图像从服务器下载,由 IE8 缓存,如果互联网断开,则从缓存中重新加载。但是,当我们从 XML 动态检索图像 url 并将其放入 URLRequest 方法时,从缓存重新加载将不起作用。
例如。 1 - 静态字符串工作
var pictureUrl:String = "http://www.server-domain/image.jpg"
public var loader:Loader;
loader.load(pictureUrl);
结果:加载图像、显示、保存在缓存中、如果互联网连接失败则从缓存中重新加载。
例如。 2 - 动态字符串不起作用
var pictureXmlList:XMLList = xml.item.image as XMLList;
var pictureUrl:String = pictureXmlList[0] as String;
public var loader:Loader;
loader.load(pictureUrl);
结果:加载图像、显示、保存在缓存中,如果互联网连接失败,请勿从缓存中重新加载。
IOError: [IOErrorEventType="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2036"]
This is my first post here in StackOverFlow, and I bring you a problem that is hauting my development team.
We are in a project, using stand alone FlashPlayer as a news displayer.
The news feed is a dynamic XML returned from a ASP.Net request and runs on Windows XP.
The problem is:
- The display is running in a bus screen and sometimes the internet connection fails, but we still need to keep displaying images from the news already downloaded. When we manually put a string on a URLRequest it works. The image is downloaded from the server, cached by the IE8, and re-loaded from cache if the internet is gone. But, when we dynamic retrieve the image url from de XML and puts inside de the URLRequest method, the re-load from cache do not work.
eg. 1 - Static string working
var pictureUrl:String = "http://www.server-domain/image.jpg"
public var loader:Loader;
loader.load(pictureUrl);
RESULT: load image, display, save in cache, re-load from cache if internet connection fails.
eg. 2 - Dynamic string NOT working
var pictureXmlList:XMLList = xml.item.image as XMLList;
var pictureUrl:String = pictureXmlList[0] as String;
public var loader:Loader;
loader.load(pictureUrl);
RESULT: load image, display, save in cache, DO NOT re-load from cache if internet connection fails.
IOError: [IOErrorEventType="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2036"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试的一件事是利用 Flash 的缓存(称为“本地共享对象”),而不是依赖浏览器的缓存 -
http://www.bestflashanimationsite.com/tutorials/4/
您可以在那里找到一些建议。这样,它就不必提取 XML 文件来获取 URL - 您会将其保存在内存中。
我不确定这是否对您有帮助,但它至少应该拓宽您的选择! :)
One thing you could try is making use of Flash's cache (called "Local Shared Objects") instead of relying on the browser's cache -
http://www.bestflashanimationsite.com/tutorials/4/
You can find some advice there. That way it doesn't have to pull in an XML file to get the URL - you'll have it in memory.
I'm not sure if that'll help you or not, but it should at least broaden your options! :)