select 很多文件时 Adob​​e Air 应用程序关闭

Adobe Air application close when select a lot of files

在我的应用程序中,当我加载大量文件(超过 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);
    }

}

加载多个文件有限制吗?

如果选择多个文件导致应用程序崩溃,我只能想到一些解决方法...

选项1)为什么不改变逻辑?尝试为:

  • 用户将从所需文件夹中 browse/selects 一张 jpeg。
  • 然后您的应用会自动扫描同一个文件夹,以在每个文件自己的特定 file.namefile.url 文本中获取所有带有文本 .jpg 的文件名。

选项 2) 使用外部程序获取文件名列表。如果你在 Windows 上,你可以使用命令行( 例如: cmd.exe 及其 dir 选项)。像...

E:\ 驱动器的 myImagesFolder 使用 cmd.exe /K "cd /d e:\myImagesFolder\" 到 运行 命令行。
然后使用 dir *.jpg 获取所有列表文件夹中的 jpeg。

也许将命令行输出接收到您的 AIR 应用程序可以解决崩溃问题?

下面的代码未经测试,但您希望此逻辑用于命令行输出:
(不会弹出终端 window,它是 silent/invisible 运行 但是您可以在任务管理器中看到 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...                     
}