2012-06-27 18 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); 
} 
相關問題