2012-06-27 37 views
3

我在Windows上使用4.1 SDK在Flash Builder 4中创建了一个Android应用程序。应用程序首先从互联网下载一些图像并将其保存在desktopDirectory中。现在我想在我的Flex移动应用程序中显示下载的图像。使用nativePath在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" /> 

因此图像是有,但该路径不被编程解决:

然而,当我硬编码图像路径在如下的代码被显示的图像。

我在做什么错?请指导。

我在android平板电脑上测试我的应用程序。

回答

3

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