2013-06-05 64 views
0

我正在使用flex 4.5.1。我在我的Flex应用程序中有图像。我发出一个http请求,并检索位于项目工作区中assets文件夹下的图片的文件路径。我在屏幕上也有一个标签,我在更新图像的同时进行了更新。通常它们应该同时更新,但图像在更新标签后1或2秒更新。Flex 4.5从资源文件夹加载图片花费太多时间

下面的代码是图像及其与初始源文件ID:

<s:BitmapImage id="personImage" visible="true" left="10" right="10" top="10" bottom="10" 
           fillMode="scale" scaleMode="stretch" source="assets/TT.jpg" 
           verticalAlign="bottom" verticalCenter="10"/> 

我设置了相关图片如下:

if(fileExist){ 
     personImage.source=lastEntranceService.lastResult.person.image; 
     personImage.validateNow(); 
}else{ 
    personImage.source = "assets/TT.jpg"; 
     personImage.validateNow(); 
    } 

lastEntranceService.lastResult.person.image; //is the filepath of the image file 

我使用验证功能太多,但我记得在某处我读的论坛是flex图像异步加载。 有没有什么方法让我在标签更新后立即在屏幕上显示图像。我有一个时间限制,所以我不能等待图像更新,然后更新标签。 图像尺寸不同,这意味着资产文件夹中的图像不同。当在屏幕上显示时,图像(需要显示)被调整为一定的大小。

谢谢你的关注和你的时间。

+0

将你的图像嵌入到编译好的应用程序中怎么样? – duTr

回答

0

您必须首先加载,比设置位图源和标签文本。

private var timStart :uint; 

private function click() { 
    bitmapLoader = new Loader(); 
    bitmapLoader.load(new URLRequest(lastEntranceService.lastResult.person.image)); 
    bitmapLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded); 

    timStart = getTimer(); 
} 

...

private function loaded(e :Event) { 

    var timeNeedToLoad:uint = getTimer() - timStart; 

    personImage.source = bitmapLoader; 
    label.text = 'Bitmap: '+ lastEntranceService.lastResult.person.image; 
} 

编辑:

入住时需要加载。

+0

谢谢你的回答。这不会减少图像的加载时间。它只是等待图像被加载到更新标签。我最初需要的是在更新标签时立即加载图像。这可以被认为是没有时间限制的同样问题的解决方案吗? – Eneramo

+0

加载其他格式(如png)或位图大小较小时,时间会有所不同吗? – marbel82

+0

我只使用jpeg文件,我认为它可能有更好的性能。还有一件事,我忘了提及图像大小可以在资产文件夹中有所不同,他们都调整到一定的大小。 – Eneramo

相关问题