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

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

问题描述

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

According to the adobe flex docs: http://livedocs.adobe.com/flex/3/html/help.html?content=controls_15.html

多次使用图片

您可以通过每次使用正常的图像导入语法在应用程序中多次使用相同的图像.Flex 只加载一次图像,然后根据需要多次引用加载的图像.

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.

但是,在测试中我们发现如果您在 IE flash 9/10 中请求相同的图像(相同的 url 等),则不会发出新的 http 请求,但在 Firefox、Safari(PC 和 MAC)中总是发出新请求.

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.

我想防止每次尝试使用图像时从服务器中拉出图像有人知道为什么这只能在 IE 中工作吗?

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?

推荐答案

一种解决方法是通过保存原始实例的 BitMapData 并将其用作后续实例的源,使用 ActionScript 创建您自己的图像缓存:

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天全站免登陆