Dynamically add files to the FileReferenceList class - actionscript-3

I was wondering that if there is way to add/select files to filerefernce instead of using filereference.browse().
Usage: I have to pick all files from a directory to be uploaded.
Thanks
Siddharth
Edit: Or is there any other way of uploading all files in a directory (num of files not more than 25)

You must use FileReferenceList.browse() method.
Flash Player creates an array of selected files called FileReferenceList.fileList

Related

AS3 - read unknown number of files from assets folder

Using ActionScript 3 I want to access multiple text files from a subfolder within my assets folder: project/src/assets/myFiles/
I know how to embed and read one specific text file if I know the exact file name:
[Embed(source="assets/myFiles/file1", mimeType="application/octet-stream")]
private static const FILE1:Class;
private function read():void {
var text:String = (new FILE1() as ByteArray).toString();
}
Since I have multiple files in the folder myFiles I'd like to read all of them.
I don't know the exact number and names of these files at compile time.
Is it possible to access them by retreiving an array of objects? Or is it possible to list all the file names read them otherwise?
Since I don't know the names at compile time I don't know how to embed and access those files.
Example of my files:
project/src/assets/myFiles/file1
project/src/assets/myFiles/file2
project/src/assets/myFiles/anotherFile
Edit: I am using AIR.
Edit: I am using Flex.
Edit: Current approach is to not use the asset directory but a dedicated (further) directory. I include this folder in the package so it and its content is automatically created in the application directory on compililation / installation. I read this folder via FileStream as suggested within the comments by Organis.

Include JSON file to build/output directory without import

Maybe the title is a bit strange, but I can't seem to find anything about on google.
Question: I have a folder that only contains .ts files and .json files.. Typescript compiles the .ts files and puts it into a separate directory (not as a bundle, just the directory structure 'as-is').
Src /
Workers /
[ModuleA.ts, ModuleA.json],
[ModuleB.ts, ModuleB.json],
[MobuleC.ts, ModuleC.json]
Most of the time I can just require('*.json') and the JSON file will be also placed in to build directory.
But now I have a situation, where importing the JSON will make no sense, because the JSON file gets updated every few seconds and I read the file with fs.readFile('*.json'), so I also don't want it floating around in the v8 cache (through require)
So how do I 'include' a JSON/None-Typescript file into the build, that is not explicitly being importing by either require or import?
For now I just used gulp to copy every .json file in the src folder over to the the respective dist/** folder.
But still find it strange typescript doesn't have something included for it..
Maybe you should checkout --resolveJsonModule, it's a newer feature of typescript.

How do I get access to assets added to a library?

I have a main project and an external library. I have added a directory of assets to the external library in src/assets/[50 files here].
When I do that, I go into the external library properties and select the folder and this includes all the files in that directory. Example shown (1 file selected):
In my main application I want to access that folder and copy the files into another directory. How do I access those files?
Note:
I may update these files periodically, copying the files and pasting them into that directory. There may be a few more or less files each time. So I'm against embedding them.
Go to your main project > Properties and select Flex Build Path. Under Source path, choose Add Folder... and enter the following
${DOCUMENTS}\GigaLibrary\src\assets
(assuming your library project is called GigaLibrary, that is)

Load all images from internal application

I am trying to load all the .png files from an internal application folder into a list control and I am stuck on exactly how to do it. I have tried httpservice to get the folder and count how many images there are so I can loop through them but I just cant figure that out.
File structure
-src
-(default package)
-my application files
-icons
-all my .png files
httpService i tried:
<s:HTTPService id="loadAllImages" destination="/icons" result="gotImages(event)" fault="loadAllImagesFault(event)"/>
This always results in directory not found. Am I going about this completely wrong? Anyone have a suggestion?
You can't do this. To store an image within an Flash application (SWF or AIR), you must embed it either using #Embed('') in MXML or by using the [Class] method.
The only way to actually reveal a folder directory of an internal folder in an AIR app is by using File (which is an AIR only class).
var file:File = File.applicationDirectory;
file.browseForDirectory('icons'); ; //unsure if that will pull an internal folder or not, but you get the idea
If this is an external directory (doesn't sound like it is), I believe you would do it how you show in your question (although I have never needed to use this method, so I don't know if/how it works)

turn folder into a zip file

I have a folder on my desktop and i want to convert it into a .zip file. It shouldnt ask me were to save it but just save it straight to my desktop or any folder i specified.
I tried ASZip, fZip etc. but i can't get it to work. There isn't any of them that seem to let me just add a folder and zip it.
I was only able to create a byteArray wit ASZip but when i saved it, it left me with a file that was not able to be opened.
Would it be possible to achieve what i want without the use of an external library?
Any help would be appreciated.
You can't actually zip a folder but you can zip all the contents inside the folder. You would have to use FileReferenceList to load in flash all the files inside the folder.
FileReferenceList allows you to have multiple selection in the browse window.
Then you would have to pass all these files to the zip managing library and get a ByteArray from it.
This byte array you would localy dump inside a "yourFileName.zip" by using FileReference.save().
The application cannot save the file to a predetermined location. The user has to pick the location using the "save to" prompt.