how to display name and score in as3 - actionscript-3

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.

Related

as3 store an external variable and keep it

I dont know if this is possible, but i have an SWF file which i want it to get info from an xml file only one time and then store it(keep it) there until a "newer" data will push into it
I know it sounds stupid but maybe there is a solution i don't know of...
1) i don't want to load the xml every time because of loads of traffic we have(a lot...will cost a lot to refresh everytime from amazon s3)
but how do we get a newer data without checking the external xml file?
2) if there was a way to broadcast(to "ping") to the swf that an update of the xml is ready to load....
if anything i believe there should be an AS3 script for that.
thanks!
but how do we get a newer data without checking the external xml file?
You could implement data file versioning. For example: urlToXmlData + "?version=" + myCurrentVesion As soon you ship new version of the application with extended data, it will work. It's global solution, so every new version of your product will work with latest data.
As for ping, you could create update strategy, for example: link is valid for 1 day. Idea is the same, concatenate stuff to the link, so browser will evaluate it as new: urlToXmlData + "?stamp=" + timestampForToday Tomorrow will be another timestamp, and browser will download updated version.
Use second xml which will contain the version first xml
I think you don't get the real subject.
You can't update a flash project without using any external update platform.
Because you cannot save all new XML data to a shared object because of "limitation of mb per data", so, flash going to delete all loaded data when application closed.
You cannot make a "permament update" in flash for "big files"...
BUT
You can update your main swf file with "EMBEDDED XML" files. Only that keeps your data updated when application is closed.
BUT that's not enough alone, also you need a "PRE-CHECK for Version of SWF" file, and that's what you can't do alone. You need a web platform featuring that way.
Mochi's "Live Updates" was offering that, but i couldn't make it work. But mochi is shutdown now... So forget about it...
I understand that your XML is BIG and you want to save trafic.
But how about small calls ?
You can have a call just to get the MD5 of your xml which is stored on the server.
Something like: myserver.com/getMD5
Once the server will return you a different md5 than the one you have already stored, then you reload xml and save new MD5.

Save PDF local method using alivepdf, flash as3

I have tried few things but no success.
I want to prompt user on button click event to save PDF file in local computer generated from object array which were created by user at runtime.
Any sort of help is greatly appreciated
Thanks
I have revised target flash player 10.0 in the html and somehow found out that the save event call has to be on button click event and I already have that. but still it gives me error and does not even generate swf file.
Here is the code and error.
1061: Call to a possibly undefined method save through a reference with static type flash.net:FileReference. It gives me this error.
var cFile:FileReference = new FileReference();
var gBytes:ByteArray = this._myPDF.save(Method.LOCAL);
cFile.save(gBytes,"test.pdf");
You can try the following, if you want to make download by using specific URL(where file is stored).
var urlRequest:URLRequest = new URLRequest("your_pdf_url");
fileRef = new FileReference();
fileRef.download(urlRequest, "your_file_name.pdf");
If you just want to prompt user to save the file in local system, you can try FileReference for that.
like :
file = new FileReference();
file.addEventListener(Event.COMPLETE, completeHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
file.save(mc, "myMovieClip");
here mc is any type of data you can provide, in your case you can provide your dynamically generated PDF file, and "myMovieClip" is name which you wan to give that file.
try this, might be useful for you.
I was using CS3 and changing the target player to 10 in HTML but found out that can not be simple. The compiler should have 10.0 as an option so I had to jump to CS6 and it worked as Vipul suggested. target player I had to keep 10.3. I had to change one more thing which is not related to this PDF saving. And that is VideoEvent to Event. I am wondering why adobe had to change that for FP 10 and above. Good to know if anybody want to use. Event.COMPLETE not VideoEvent.COMPLETE once again thanks a lot Vipul I will check the second import statement flash.utils.ByteArray. I must have because I did not get any error

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.

Adobe Air Global Application Data

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.

How can I 'force download' a file that has been generated entirely in Flash?

If I'm generating a binary file inside Flash Player, how do I pop up a 'Save' dialog for the file without sending it up the the server first?
I'm sure I heard this was a new feature in Flash 10.
Cheers,
James
This will help, and really show you how to do it, all you have to keep in mind is that opening and saving files can only be done with user initiation, it cannot be automated, so not sure what you are trying to do, but this will help:
http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/
If you are inside the flash player, you can do the following:
import flash.net.FileReference;
import flash.utils.ByteArray;
var fileReference:FileReference = new FileReference();
var data:ByteArray; // load up your data into this ByteArray
fileReference.save(data, "outputfile.dat");
This will not work if you are running in the browser-- at least as far as I remember, but if you are in the flash player this will work.
The FileReference.save() method will popup a dialog for the user to choose where to save the file, so the filename given is just a suggested filename.
Edit: See Technomaag's comment below also if you're having problems