AS3 write string to an existing text file - actionscript-3

I'm running my program on AIR. I want my game to save the high score to a text file so it can be stored when the program is closed. I've tried using filestreams, however I've found that the application directory is read only. Is there a better way to do this?

The AIR application storage directory is designed for saving these sorts of preferences and user settings:
For every AIR application, there is a unique associated path that
defines the application storage directory. This directory is unique to
each application and user. You can use this directory to store
user-specific, application-specific data (such as user data or
preferences files).
Access it through the File class:
var file:File = File.applicationStorageDirectory;
file = file.resolvePath("prefs.xml");
See also: Reading from and writing to an XML preferences file
The only caveat I have found with using this directory is that it does not get removed when the AIR app is uninstalled using the .air installer/uninstaller.

Related

How to access a OS X user's file system with React VR?

I'm developing an Electron app that is running an instance React VR. The app enables a user to add and save content to a react-vr project by reading and writing the state from/to a JSON file. During development, this JSON file has been stored in the root directory. However, if a user is to download and use the app on their computer, the JSON file needs to be moved outside the app package contents folder.
I have tried using app.getpath('userdata') which returns /Users/'username'/Library/Application Support/'app_name', and I can move the JSON state file there successfully upon running the app. However, I don't know how to have react-vr access this file, especially since there is no access to the computer's file system. However, all I really need is the user's system username to include in the 'userdata' file path.
What's the best way to go about retrieving the username from within react-vr? Would there be a better way to persist user data instead of a using a JSON file to keep track of the state? Would it be worth considering using AsyncStorage in conjunction with a database? Many thanks.

How to load all files in a folder with as3

I need to load a large number of pictures (around 30) in a sequence as a short movie, each .png has the size 960X540.
I don't want the loader depend on the name of each picture as I will make changes frequently.
Is there any suggestions?
Are you trying to load images from a local file system, or a remote web server?
If you want to load images from a local file system folder, you can use AIR's File/getDirectoryListing().
If you want to load images from a remote server, and you do not want to rely on a pre-defined file naming pattern, the server will need to be able to provide directory information, for example a PHP script that reads the directory contents and outputs XML or JSON. There's no general way for a client to probe a web server for files in a directory. Some web servers do have a default web directory listing script that shows when there is no "default" file in a folder (index.html, etc), but that probably won't be quite good enough for what you're trying to do.
As a final note, if you don't mind manually updating a file on the server that lists all the files as XML or JSON, you could create a simple AIR app to process a local file directory and generate the necessary XML or JSON and upload that to your server.

Is there a way to create a directly accessible URL to a file stored as varbinary(max) in a mySQL database?

I have a number of different types of files stored in a MySQL database (varbinaryMAX). I am in the process of building a document management system and my final phase is to install some sort of document viewer so that these files can be prievewed.
I have veered away from Google Docs due to the security of the documents. I have [preliminarily] settled with Viewer.JS as my chosen method of preview as it supports a wide variety of filetypes, and is free. It does however require a directly accessible URL for the file, which I of course dont have as the file is sitting in a coloumn in the DB.
How would I go about generating a URL that can be used to access a/the file in the DB?
Application is ASP.net

Accessing files from Windows Store App

I'm working in Windows 8 Operating System building Windows Store apps.
I'm trying to access one XML file(present within the solution) via the code below.
var file = System.Xml.Linq.XDocument.Load(#"E:\Gowtham\Data.xml");
But I'm getting "Access to the path 'E:\Gowtham\Data.xml' is denied.'" exception.
I tried all possible ways to remove the read-only attribute of the folder and the file but no use.
I used command prompt to change the attributes of the file, also I tried manually but the read-only attribute of that folder is not changed.
Kind help pls.
You can't get ANY file like that way. I highly recommend you to read these links. You can access files from library if you have declared library access capability.
File system places accessible through WinRT API
Windows 8: The right way to Read & Write Files in WinRT

Create text file in swf that downloads to users computer

Is it possible to create a text file on the fly in swf/flash running in a users’ browser and prompt the user to download the file to his computer?
I am familiar with the FileReference class, but I cannot figure out a way for this class to work without reading the file to be downloaded from a server.
Edit: For this to fully work in my use case the swf/browser should handle the file more or less like a file downloaded from remote servers - meaning that it should prompt the user and ask what he would like to do with the file and give the option to open file in default application (or open automatically if that is what the user has set as the default action for such files).
Try this:
var file:FileReference = new FileReference();
file.save("this is a text", "file.txt")