使用nativePath在Flex移动应用中无法显示图像

3
我正在使用Flash Builder 4和4.1 SDK在Windows上创建一个Android应用程序。该应用程序首先从互联网下载一些图像,并将它们保存在desktopDirectory中。现在,我想在我的Flex移动应用程序中显示已下载的图像。
问题:
成功地从互联网下载图像并将其成功保存在desktopDirectory中。
现在,当我尝试使用nativePath显示图像时,图像并未显示。显示的是一个带有问号的小蓝色图标。我所使用的代码如下:
displayContainer.removeAllElements();
var image:spark.components.Image = new spark.components.Image();
var imageFile:File = File.desktopDirectory.resolvePath(desktopFilePath);
if(imageFile.exists)
{
    var imagePath:String = File.desktopDirectory.resolvePath(desktopFilePath).nativePath;

    image.source = imagePath;
    trace("Image Path: " + imagePath);
    displayContainer.addElementAt(image,1);
}

当我追踪图像文件是否存在时,显示该文件已经存在。但是应用程序中没有显示该文件。

然而,当我在代码中硬编码图像路径时,图像会显示如下:

<s:Image id="a1" source="data/02.jpg" />

因此图片已存在,但路径并未被自动解析。
我做错了什么?请指导我。
我正在一款安卓平板上测试我的应用程序。
1个回答

3

我解决了我的问题,不再使用文件本地路径,而是使用文件URL。请见下面的代码:

displayContainer.removeAllElements();
var image:spark.components.Image = new spark.components.Image();
var imageFile:File = File.desktopDirectory.resolvePath(desktopFilePath);
if(imageFile.exists)
{
    var imagePath:String = File.desktopDirectory.resolvePath(desktopFilePath).url;

    image.source = imagePath;
    trace("Image Path: " + imagePath);
    displayContainer.addElementAt(image,1);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接