0

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

以下代码是带有初始源文件的图像及其 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 图像是异步加载的。标签更新后,我有什么方法可以在屏幕上显示图像。我有时间限制,所以我不能等待图像更新然后更新标签。图像的尺寸不同,这意味着资产文件夹中的图像是不同的。当显示在屏幕上时,图像(需要显示)被调整为某个恒定大小。

感谢您的关注和时间。

4

1 回答 1

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;
}

编辑:

检查时间需要加载。

于 2013-06-05T12:32:31.820 回答