如何摆脱flex中的#2038错误

时间:2012-11-19 12:43:13

标签: actionscript-3 flex flex4.5

这是我的代码: 我创建了一个flex移动应用程序,我想在ipad / iphone(任何IOS设备)中保存pdf格式的文件 但保存该文件时,它通过#2038错误。 这是我的代码。

var file:File = File.desktopDirectory.resolvePath("indicators.pdf");

if (file.exists)
 file.deleteFile(); //delete it if exists
//create a file stream to be able to write the content of the file    
var fileStream:FileStream = new FileStream();

var popUpPage:AlertPage = new AlertPage();

try
{
 //open the file stream and set for Write
 fileStream.open(file, FileMode.WRITE);
 //writes the bytes
 fileStream.writeBytes(pdfBytes, 0, pdfBytes.length);
 //close the stream
 fileStream.close();

 PopUpManager.addPopUp(popUpPage,this,true);
 popUpPage.lblAlert.text = "indicator saved in pdf format = "+ file.nativePath;
 PopUpManager.centerPopUp(popUpPage);
 this.visible = false;
}
catch(err :Error)
{
 PopUpManager.addPopUp(popUpPage,this,true);
 popUpPage.lblAlert.text = err.message + "  "+ file.nativePath;
 PopUpManager.centerPopUp(popUpPage);
}

2 个答案:

答案 0 :(得分:0)

您无法在任何移动设备上保存到desktopDirectory。您的应用仅允许保存到applicationStorageDirectory。由于这个原因,你每次都会出错。

作为一个简单的技巧,你应该这样做以允许两者。

private const isDesktop:Boolean = false;
private var baseDirectory:File = ( isDesktop ) ? File.desktopDirectory:File.applicationStorageDirectory;

//and to declare a file, do this
private var pdf:File = this.baseDirectory.resolvePath( 'blah.pdf' );

因此,您切换isDesktop属性以选择要使用的属性,并相应地声明baseDirectory。然后,您每次只需从baseDirectory解析路径,而不是使用硬编码applicationStorageDirectorydesktopDirectory

从长远来看,这种方法对于调试来说更加灵活。

答案 1 :(得分:0)

在我们的桌面环境(Flex-Desktop应用程序)中不确定权限如何在Android BUT上运行,我们能够通过修复文件夹权限来消除错误(为用户提供读写修改权限)