如何控制Flex 3图像控制缓存 [英] How to Control Flex 3 Image Control Caching

查看:180
本文介绍了如何控制Flex 3图像控制缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Adobe Flex文档: http: //livedocs.adobe.com/flex/3/html/help.html?content=controls_15.html



多次使用图片



通过每次使用正常的图像导入语法,您可以在应用程序中多次使用相同的图像。 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);
}

我创建了一个功能完整的示例,并发布了源代码 here


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图像控制缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆