问题描述
根据Adobe Flex文档:多次使用图片
通过每次使用正常的图像导入语法,您可以在应用程序中多次使用相同的图像。 Flex仅加载一次图像,然后根据需要多次引用加载的图像。然而,在测试中,我们发现,如果您请求相同的图像(相同网址等)在IE浏览器9/10新的http请求将不会发布,但与Firefox,Safari(PC和MAC)总是发出一个新的请求。
我想防止每次我尝试和使用它时,从服务器拉图像任何人有任何想法,为什么这只是在IE浏览器?
一个解决方法是使用ActionScript创建自己的图像缓存,方法是保存原始实例的BitMapData,并将其用作后续实例的源代码:
private var image1:Image = new Image();
private var image2:Image = new Image();
private function init():void
{
image1.addEventListener(Event.COMPLETE,onComplete);
image1.source =icon.png;
addChild(image1);
$ b private function onComplete(event:Event):void
{
var image:Image = event.target as Image;
var bitmapData:BitmapData = new BitmapData(image.content.width,
image.content.height,true);
bitmapData.draw(image.content);
image2.source = new Bitmap(bitmapData);
addChild(image2);
}
我创建了一个功能完整的示例,并发布了源代码。
According to the adobe flex docs: http://livedocs.adobe.com/flex/3/html/help.html?content=controls_15.html
Using an image multiple times
You can use the same image multiple times in your application by using the normal image import syntax each time. Flex only loads the image once, and then references the loaded image as many times as necessary.
However, in testing we have found that if you request the same image (same url, etc.) in IE flash 9/10 a new http request will not be issued, but with Firefox, Safari (PC and MAC) a new request is always issued.
I want to prevent the image from being pulled from the server each time I try and use it anyone have any idea why this is working only in IE?
One workaround is to create your own image cache with ActionScript by saving the BitMapData of the original instance and using it as the source for subsequent instances:
private var image1:Image = new Image();
private var image2:Image = new Image();
private function init() : void
{
image1.addEventListener(Event.COMPLETE, onComplete);
image1.source = "icon.png";
addChild(image1);
}
private function onComplete(event:Event) : void
{
var image:Image = event.target as Image;
var bitmapData:BitmapData = new BitmapData(image.content.width,
image.content.height, true);
bitmapData.draw(image.content);
image2.source = new Bitmap(bitmapData);
addChild(image2);
}
I created a fully functioning example and posted the source here.
这篇关于如何控制Flex 3图像控制缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!