Search code examples
apache-flexactionscript-3air

how to download files to a default dir without poping an option window in Flex/Air?


I'm writing a app with Flex/air,and i need a function that downloading files to the default dir without a pop-up window.i tried to use ftp instead of http but found it's not supported by air.how can i solve this problem?


Solution

  • This should be possible in AIR. I don't know if there's a direct API approach, but you should be able to load the bytes into memory and then flush them into a file. In pseudo-pseudo-code using File and FileStream:

    // get the bytes
    var loader:URLLoader = new URLLoader();
    loader.load("http://www.stackoverflow.com");
    ...
    var bytes:ByteArray = loader.data;
    
    // get the file in the correct location
    var f:File = File.documentsDirectory.resolvePath("myfile.txt");
    
    // write the file
    var fs:FileStream = new FileStream(f, FileMode.WRITE);
    fs.writeBytes(bytes);
    fs.close();
    

    There are a few examples out there to look at.

    None of this is possible in Flash Player because of the security limits @viatropos suggests.