在我的应用程序中,当我加载很多文件(超过100个文件)时,应用程序会自动关闭。
我正在使用FileListEvent.SELECT_MULTIPLE,此应用程序仅用于获取文件名。
function selectFile(e: MouseEvent): void {
file_selected.browseForOpenMultiple("Selecionar fotos:", [jpgFilter]);
file_selected.addEventListener(FileListEvent.SELECT_MULTIPLE, onFileSelected);
}
function clearTextArea(e:MouseEvent):void {
textArea.text = "";
txt_folder.text = "";
}
function onFileSelected(e: FileListEvent): void {
trace("test");
for (var i:uint = 0; i < e.files.length; i++)
{
//trace("NOME: " + e.files[i].name);
obj_list.push({file_name:e.files[i].name});
}
fileInformation(obj_list[email_number].file_name);
}
function fileInformation($name:String):void {
var domain_name:String = "";
var file_name:String = $name;
var nome:String;
var email:String;
if(file_name.indexOf(divisor) != -1){
nome = file_name.slice(0, file_name.indexOf(divisor) - 1);
email = file_name.slice(file_name.indexOf(divisor) + 2, file_name.length).toUpperCase();
}
if(email.indexOf("(") != -1){
email = email.slice(0, email.indexOf("(") - 1);
}
trace("Nome: " + nome);
trace("Email: " + email);
textArea.appendText(String("\n" + email).toUpperCase());
email_number++;
if(email_number <= obj_list.length - 1){
fileInformation(obj_list[email_number].file_name);
}
}
加载多个文件有限制吗?
答案 0 :(得分:0)
如果选择多个文件使应用程序崩溃,我只能想到一些解决方法...
选项1)为什么不更改逻辑?试试:
.jpg
或file.name
文本中带有文本file.url
的所有文件名。选项2)使用外部程序获取文件名列表。如果您使用的是Windows,则可以使用命令行(例如: cmd.exe
及其dir
选项)。像...
使用cmd.exe /K "cd /d e:\myImagesFolder\"
从E:\
驱动器的myImagesFolder
运行命令行。
然后使用dir *.jpg
获取文件夹中所有jpeg的列表。
也许将命令行输出接收到AIR应用程序中可能是崩溃问题的解决方法?
以下代码未经测试,但您希望此逻辑用于命令行输出:
(不会弹出任何终端窗口,这是静默/不可见的运行,但您可以看到任务管理器中列出的cmd.exe
) :
var file_selected :File = File.documentsDirectory;
var user_Folder_Path : String = ""; //# update with User folder path (after they selected 1 file)
var str_Temp : String = "";
var str_Files : String = "";
var processInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var processArgs:Vector.<String> = new Vector.<String>();
var process:NativeProcess = new NativeProcess();
function selectFile (e :MouseEvent) :void
{
file_selected.browseForOpen("Selecionar fotos:", [jpgFilter]);
file_selected.addEventListener(Event.SELECT, fileSelected);
}
function fileSelected(event:Event):void
{
str_Temp = fileToOpen.nativePath;
//# trim down to folder path eg: remove file name part
user_Folder_Path = str_Temp.substring(0, str_Temp.lastIndexOf("\") );
str_Temp = str_Files = ""; //reset both strings
if(NativeProcess.isSupported)
{
processInfo.executable = new File("C:/Windows/System32/cmd.exe");
processArgs.push("dir *.jpg" + " " + user_Folder_Path );
processInfo.arguments = processArgs;
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, std_onStandardOutputData);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, std_onError);
process.start(processInfo);
process.standardInput.writeUTFBytes(processArgs + "\n");
}
}
function std_onStandardOutputData(evt:ProgressEvent):void
{
var process:NativeProcess = evt.target as NativeProcess;
var data:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
str_Files += data; //holds file names as they come in from CMD.exe
}
function std_onError(evt:ProgressEvent):void
{
var process:NativeProcess = evt.target as NativeProcess;
var data:String = process.standardError.readUTFBytes(process.standardError.bytesAvailable);
str_Temp += data; //holds other text data from CMD...
}