AS3 - read unknown number of files from assets folder - actionscript-3

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.

Related

How can I use a Liquid-generated JSON as a "_data" site.data object in Jekyll?

Using Liquid, I am trying to build a JSON object (skills.json) containing data from all of my Jekyll posts.
When I place this file in my _data folder in my project root directory per https://jekyllrb.com/docs/datafiles/, trying to access the data via site.data.skills with the inspect filter or console log resolves to nothing.
final output section of my Liquid json
When I instead place my skills.json file in the /assets/js/ folder in my root, I do see that the properly populated JSON file is added to my _site folder as expected. Copying this NEW file into the root _data folder successfully populates to my page as intended, and I am able to access all the data with site.data.skills.KEY.
json generated from assets folder at build time
Is there any way that I could specify that the generated skills.json in my /assets/js/ folder be the source for my data call?
Alternatively, is there a way to generate the final data and automatically move it to the _data folder ahead of building the site? I am open to any suggestions for how to automate this. As a warning, I am pretty new to web development in general, so any references or links would be a tremendous help. Thanks!
Following up on this, I believe that the issue lies in how the site is built. The skills.json file gets generated on the first build, and then when it is added to the _data folder, the site gets built AGAIN to update everything that hits that data. With this iterative process, I don't know if it would be possible to both generate the new file and use it as a source to update everything dependent on the data in the same pass.
As far as automating goes, my thinking is that a Ruby plugin to compare the newly generated files against the _data folder and overwrite if the source is different/newer would be the way to go, but I'm still open to any suggestions!

Store files in database with DBIC using Catalyst

I'm using Perl Catalyst framework to build an application that needs to store several files in a MySQL database (among other things). I want to store the name, path, extension, etc of the files to retrieve them later; because they are supposed to be accessible from the application (e.g: a PDF document uploaded for someone, must be available for download later). Can I do this? I found several ways to do it in PHP, but none for perl. Any ideas?
EDIT
I know I can access to some information using Catalyst::Request::Upload. I used this in the past for BLOB storage, but I dont't know how to get file information nor how to know where does catalyst store tmp files.
So, basically, the questions that arise when trying to this are:
How to know where are my files being stored once I submit them?
How to copy these files (which I assume go to a tmp folder somewhere) to a folder in my computer/server?
How to retrieve these files once I have them stored?
EDIT 2
I've checked again the documentation for Catalyst::Request::Upload (http://search.cpan.org/~jjnapiork/Catalyst-Runtime-5.90114/lib/Catalyst/Request/Upload.pm) and found out how to know where are my files being stored and how to copy them to a new non-tmp location. The only question that remains:
How do I generate a download link for these files??
The solution was pretty straight-forward.
First Make sure your 'tmp' folder is configured in the Catalyst app file (e.g: MyApp.pm).
Now, use Catalyst::Request::Upload to create the file object with the uploaded file. Sort of...
my $upload = $req->upload('input_field_name');
Now make sure you get all the data you want to store from the file. I, personally, got just the filename, MIME Type and size.
my $filename = $upload->filename;
my $size = $upload->size;
my $type = $upload->type;
Store into the database.
Now, create a folder within the public content of the page to copy the files to, and perform the copy like:
$upload->copy_to('path/to/the/public/folder');
To retrieve the files, just create a link with the base URL to the public folder and the filename you stored in the database.
Hope it helps someone... it was pretty obvious, though; but it cracked my head a little.

Access asset / resource file in an ActionScript Library project

I'm using an ActionScript Library project to share code and assets / resources between a Mobile and a Desktop ActionScript projects.
The library project has been added to the two other projects via the 'Add Project' option on the 'Library Path' tab, with the linkage type 'Merged into Code', and all the classes within it can be accessed by the other projects, and work properly.
However it contains a SQLite database file, which I want to copy out to the File.applicationStorageDirectory on the target system on the first load of the app, and I'm not sure how to get a reference to the file within the library project to copy it out.
The location of the db file is: LibraryProj - src/database/dbFile.db and I thought using File.applicationDirectory and then a path 'into' the swf would give me access to it, but none of the following tests say the file exists.
var test:File;
test = File.applicationDirectory.resolvePath("app:/src/database/dbFileDb.db");
trace("test.exists==" + test.exists);
test = File.applicationDirectory.resolvePath("src/database/dbFileDb.db");
trace("test.exists==" + test.exists);
test = File.applicationDirectory.resolvePath("database/dbFileDb.db");
trace("test.exists==" + test.exists);
test = File.applicationDirectory.resolvePath("dbFileDb.db");
trace("test.exists==" + test.exists);
Is this the correct method to copy resource / asset files out of a swf containing merged libraries and onto the app's storage directory? Is it even possible to share resources / assets from Library projects in this way?
Any advice would be very much appreciated.
After doing some more research about using the [Embed] tag in AS3, I've now worked out that this is what I should have been using to make the file available to consuming projects (I'd previously only used it for images, and didn't think of it for other file types too).
[Embed('igniteDb.db', mimeType="application/octet-stream")]
public static const myReferenceDbFile:Class;
To copy the file to the File.applicationStorageDirectory i'm using the following code. It converts the embedded file to a byte array, and then writes this out via a FileStream class to the destination file.
//write the embedded database file data into app user files directory
var bundleDbBytes:ByteArray;
bundleDbBytes = new myReferenceDbFile();//gets a reference to the embedded db file
var outputDbFile:File = File.applicationStorageDirectory.resolvePath(DB_FILE_NAME);
var fileStream:FileStream = new FileStream();
fileStream.open(outputDbFile, FileMode.UPDATE);
fileStream.writeBytes(bundleDbBytes);
fileStream.close();
And hey presto, the database is ready to use.

Dynamically add files to the FileReferenceList class

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

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)