Adobe Air Global Application Data - actionscript-3

Does anyone know of a "Global" Application data for Adobe Air?
File.applicationStorageDirectory stores within the users area?
But we need the application to store information for the whole computer.
Something such as Windows: C:\ProgramData or AllUsers but there doesn't seem to be an official way to use these areas. (Trying to keep this as Standard as possible)
But there doesn't seem to be a File.allUsersApplicationStorage or File.globalApplicationData anything.
Now I know I could do something such as below for Windows Vista/7
var _path:String = File.applicationDirectory.nativePath;
// _np: C:\Program Files (x86)\ProgName\
_path = _path.substr(0, _np.indexOf(File.separator) + 1);
// _np: C:\
var _file = new File(_path).resolvePath("ProgramData/ProgName");
but I do not know what to do for WinXP, MacOS or Linux.
Any help would be welcome.

Couldn't you just use File.applicationDirectory? (Or rather, a subdirectory of it.) That would store your information in the application directory, and would be accessible from all users.
It might not be ideal, but it works.

Related

How to change ID in "application.xml" to run multiple instance of an AIR application?

I wants to run more than one instance of my Adobe Air Application, So to do this it needs to be change the ID in "application.xml" file of the application which is present in the folder META-INF of installation directory.
But i don't know how to change this ID at run-time.
Does anyone have an idea how to do this or any other process is there to solve this problem ?
You can't change ID at run-time. The only way to run several instances is to prepare several packages with different appID in app descriptor xml - so to have several app descriptors.

how to display name and score in as3

I have a quiz in flash as3. I want to save the name and score from user when they try my quiz. If user end the quiz, I want to display the name and the score from user before. I think to use mySQL and PHP, but I don't sure it will works in another PC without internet. Can anybody help me?
UPDATE :
I solved this problem using Shared Object. It really works.
You might be interested to save datas in an external file (XML,...), this way it should be able to save any score with or without internet.
For a simple AIR flash application you can simply create an external file
var file1:File = new File("\score.dat");//you can also use File.applicationStorageDirectory
var str:FileStream=new FileStream();
str.open(file1, FileMode.WRITE);
//save your name and score here in some formatted way
str.writeUTFBytes("NAME: Feynman SCORE: 500/500 ");
str.close();
Similarly to read the file
var fileOpen:FileStream = new FileStream();
fileOpen.open(file1, FileMode.READ);
// this will contain your name/score string
var str:String = fileOpen.readUTF();
fileOpen.close();
dont forget to import flash.filesystem.File and import flash.net.FileReference.
But you should be aware of that this file is not secure it could be tampered with. You should look into more secure way to store store data if your application need it eg Shared Objects / cryptographically securing your data / storing it externally (on your servers).
You can't import flash.filesystem.File unless if don't have an AIR application.
As I know about Flash can't write and read file on computers. If you have a PHP server, you can't easily do this job with sending data's to PHP for saving on SQL and asking for data.
About this:
I think to use mySQL and PHP, but I don't sure it will works in another PC without internet. Can anybody help me?
If there isn't any internet connection on the PC, you can't use PHP or MySQL to save.
If you use PHP and MySQL to save your data's and coins ext. it's gonna always work unless the PC got internet connection.

Create new specified folder with AS3 and AIR

I am relatively new to the AIR world and need some help (on Windows 7 operating system). I tried searching for help, but I am dumbfounded as what to do. My knowledge of ActionScript 3 is fundamental and I am completely new to working with Adobe AIR. I will keep this thread short and not go into great detail about the rest of my application.
Any help is appreciated, I am completely lost.
Steps:
The user runs my Adobe Air application.
(and it does open, just the buttons don't work yet)
User clicks the "Save As" button and is prompted with a window to choose the desired directory.
After they choose the directory the directory path is stored in a String variable.
Then the user clicks the "OK" button. This will grab the path directory variable and create a new folder. The folder will have the name from a variable string.
Here is a sample code for selecting a directory
protected function browseBtn_clickHandler(event:MouseEvent):void
{
var browseFile:File = FileUtils.documentsDirectory();
browseFile.addEventListener(Event.SELECT, fileSelected);
browseFile.browseForDirectory("Select Local Folder");
function fileSelected(e:Event):void {
browseFile.removeEventListener(Event.SELECT, fileSelected);
if(localDirPath.text != browseFile.nativePath){
localDirPath.text = browseFile.nativePath;
changed=true;
}
}
}
this is a sample, localDirPath is a TextInput where I display the selected path, changed is a flag, so you use the File class in AIR for Desktop.Check the documentation File Class Reference check the methods that contain "browse" like browseForOpen, browseForSave, createDirectory

AS3 flash.net.FileReferenceList.browse() accepts an array of FileFilter objects but seems Mac OS is using only the first element

I have a file upload component written in ActionScript 3. The component is using the FileReferenceList.browse() to let the user select the files to upload. This method accepts an array of FileFilter objects to narrow down the selectable file types.
Until this time I passed only one FileFilter element in the array - if I passed any. This worked well for years without any problem. But recently I ran into a situation when I thought I understand why this method takes an array of FileFilters. Probably I was wrong...
I have a service which designed (and used) to present visual material mainly (images), but it can deal with non-visual files too like .xls, .doc, .zip, etc. This means in practice that my admin will upload almost only images (99%) to this service BUT sometimes (s)he will upload 1-2 .xls, .doc or .zip, etc.
So from this point I didn't want to really block files outside the (image) filter. Just tried to "show" my admin user that the preferred files are images here, but at the end of the day (s)he must be able to upload any file type.
So, I did this:
var fileReferenceList : FileReferenceList = new FileReferenceList();
var imgFilefilter : FileFilter = new FileFilter("Images", "*.jpg;*.jpeg;*.gif;*.png");
var allFilesFilter : FileFilter = new FileFilter("All files", "*");
fileReferenceList.browse([imgFileFilter, allFilesFilter]);
This worked well - on Windows. When the file browser window comes up my user sees the image files only. But (s)he can switch to "all files" view and upload other files too.
But now it turned out my Mac users are screwed this way... The file browser window doesn't offer the possibility to switch to "All files" view, so they can not upload non-image files :-) arghhhh!
I'm wondering what could be the best solution for the problem I tried to describe above? A trivial solution could be that for Mac users I skip the FileFilter stuff entirely. But it is not the way I would prefer... OR did I missed something? Is it possible to somehow "convince" Mac file browser window to offer the possibility let my admin choose between the filters like Win file selector does?

Protect Air application content

On Mac Os, I see that all content on my application can be readable (mxml and as files).
Indeed with right clic on application, you can see all application content and so all files.
So It's very dangerous for a company to distribute air application like that.
Is a solution exist to protect those files.
Thanks
It is not possible to protect 100% your code. After all, if the computer can run it, it can be decompiled, regardless of the language. However, you can make it more difficult.
One method is to encrypt the swf as stated in another answer. But all the "attacker" needs to do is find the key and then they can decrypt all your swfs.
Another method is to use obfuscators. Obfuscators don't depend on encryption, nor they prevent decompiling, they just make it harder to understand what gets decompiled.
For example if you had a method called saveInvoice() the obfuscator would rename it to aa1() or something like that, so it would make it diffucult to guess what that function does. It basically turns everything into spaguetti code.
You can use a decompiler to see what can be obtained from a SWF file (which is alot), and play with obfuscators to see if they meet your espectations.
An example of one is http://www.kindi.com/ which I'm not endorsing btw, it just shows up quickly on google.
Although there are loads of decompilers which can read all your code. There is one guy who came up with encryption solution it might worth a try. (It's for Desktop AIR applications)
Have a look at this post: http://forums.adobe.com/message/3510525#3510525
Quoted text (in case of page being erased)
The method I use will allow you encrpyt most of your source code using
a key that is unique to every computer. The initial download of my
software is a simple air app that does not contain the actual program.
It is more like a shell that first retreaves a list of the clients mac
addresses and the user entered activation code that is created at time
of purchase. This is sent to server and logged. The activation code
is saved to a file client side. At the server the mac address and
activation key are used to create the encryption key. The bulk of the
program code is then encrypted using that key, then divided into parts
and sent back to the client. The client puts the parts back together
and saves the encrypted file. At runtime the shell finds the mac
address list and the activation key, then using same method as server
gets the encryption key and decrypts the program file. Run simple
check to make sure it loaded. For encyption i found an aes method that
works in php and javascript.
Next I use this code to load the program
var loader = air.HTMLLoader.createRootWindow(true, options, true, windowBounds);
loader.cacheResponse=false;
loader.placeLoadStringContentInApplicationSandbox=true;
loader.loadString(page);
This method makes it very difficult to copy
to another computer although since I wrote it i know there are some
weeknesses in the security but to make it harder i obv. the shell
code. It at least keeps most from pirating. However there are issues
with this that I have found. First i was using networkInfo to get the
list of mac address but this failed in a test windows XP computer.
When the wireless was off it did not return the MAC. I was not able
to recreate this in VISTA or 7. Not sure if it could happen. Was not
tested on a mac computer. To fix this (at least for windows). I
wrote a simple bat file that gets the MAC list, then converted it to
an exe which is included. This does force you to create native
installers. call the exe with this
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
var file = air.File.applicationDirectory.resolvePath("findmac.exe");
nativeProcessStartupInfo.executable = file;
process = new air.NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
process.addEventListener(air.NativeProcessExitEvent.EXIT, onExit);
process.addEventListener(air.IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
process.addEventListener(air.IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
put the list together in the onOutputData event using array.push and
continue on the onExit event using the findmac.exe will return the
same info every time (that i know of) beware thought that using the
native install will break the standard application update process so
you will have to write your own. My updates are processed the same way
as above. This is contents of the .bat file to get the mac list
#Echo off
SETLOCAL SET MAC = SET Media = Connected
FOR /F "Tokens=1-2 Delims=:" %%a in ('ipconfig /all^| FIND "Physical Address"') do #echo %%b ENDLOCAL
using this method makes it simple to implement at try before you by
method. at runtime if no activation code get try me version from
server instead of full version.