图像未显示在使用 nativePath 的 Flex 移动应用程序中



我正在使用Windows上的4.1 SDK在Flash builder 4中创建Android应用程序。该应用程序首先从互联网上下载一些图像,并将它们保存在桌面目录中。现在我想在我的flex移动应用程序中显示下载的图像。

问题:

图像已成功从互联网下载并成功保存在桌面目录中。

现在,当我尝试使用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" />

因此,图像存在,但路径未以编程方式解析。

我做错了什么?请指导。

我正在安卓平板电脑上测试我的应用程序。

我没有使用file nativePath,而是使用了file 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);
}

最新更新