Save PDF local method using alivepdf, flash as3 - actionscript-3

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

Related

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

how to I make my flash AS3 game save progress

I have this flash game that I've been working on that works out of the browser, and I'm looking to get it to save it's progress.
I've seen multiple flash games that have accomplished this, and It appears as though they've done this client-side, and I'd like to do the same.
My game consists of 1 mxml file and a number of .as files and I compile it from the command line using flex sdk.
What do I have to do to be able to save save my game's data?
As others have mentioned, SharedObject is the tool you'll use for this.
The basics of this are to initialize a reference to a SharedObject using its static method .getLocal() first:
var mySaveData:SharedObject = SharedObject.getLocal("SomeSaveName");
The String given to this method should not contain spaces.
Once you've done this, you'll be able to use mySaveData.data, which is basically a simple object that you can attach properties to on the fly (it's dynamic):
mySaveData.data.levelsComplete = 2;
Once you've done this, you'll be able to reference that value later on using the same process:
trace( mySaveData.data.levelsComplete );
For simple stuff you can use SharedObject
One way is to use flash's SharedObject to save values in to a 'flash cookie' on the client. Example can be found here: Actionscript 3 saving currentframe location to local hard drive?

Accessing variables inside embedded SWF?

I'm programming an AS3 application which loads an external SWF file to a movie clip in my stage. I need to read a variable inside the embedded SWF. I think I can, probably, do this through the bgURL, but I can't figure out how.
How can I read a variable inside the embedded SWF?
var bgLoader:Loader = new Loader();
var bgURL:URLRequest = new URLRequest("file.swf");
bgLoader.load(bgURL);
addChild(bgLoader);
That would be something like trace(MovieClip(bgLoader.content).Player.played);, but make sure you access the content in the Event.COMPLETE handler:
bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,bgLoaded);
function bgLoaded(event:Event):void{ trace(MovieClip(bgLoader.content).Player.played) }
bgLoader.content returns a DisplayObject, but you need to access you content as a MovieClip. To do so you use casting.
This is presuming your external swf is also AS3 (good point Teo.sk !)
This bit: _root.Player.played looks like AS2. Unfortunately you can't access
variables form a loaded AS2 movie directly.
Still, you can use Local Connection class to send variables back and forth betwen
AS2 and AS3. Luckily Grant Skinner wrote a nice little utility called SWFBridge
to make this easier

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