AS3 Flash - Save JPG - actionscript-3

Im making a little game with in the end the option to take a picture of you to share. Ive succeeded in coding parts like displaying the foto on a bitmap and to save the foto.
Now the problem is that you get a save-as pop-up screen to select where you want to save your foto. But i dont want that option, i just want to save it at a specific folder on my pc. Ive come across similar questions here, to save png/jpg foto's, but none have my specific question.
Is is possible to do?
Thanks,
The.Jack

You can't save directly without a dialogue-box in web, it always asks where it should save. Because it should triggered by user due to flash security issues
But in Adobe Air it is possible to save with flash.filesystem.File and flash.filesystem.FileStream
var fileStream : FileStream = new FileStream();
var file : File = File.desktopDirectory.resolvePath('sample.jpg');
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(defined_byte_array);
fileStream.close();
Hope it helps

Related

How to load swf created with flipbook maker into flash

I'm trying to load the swf created by 'flip book maker' into my project.
the files created by flipbook maker are
book.swf
framework.swf
I used the following code
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("book.swf");
myLoader.load(url);
addChild(myLoader);``
the framework.swf is linked with book.swf, so it cannot run alone.
When I run the movie it shows the Error #2032, Stream error to framework.swf
book.swf and framework.swf both are in the same directory.They are generated by flip book maker What I needed is to load the book.swf into my project at a particular frame. I need help in AS3 for this purpose.
How to fix it..?
please help me..!
Error #2032 means that your Flash application could not load the framework.swf for some reason (you know this already of course). What you need to find out is why. Possible reasons are: you have the wrong URL, the framework.swf is not in the place you expect, there are crossdomain restrictions on the file you are trying to access ( you did not state where frameworks.swf).
What I would suggest doing is using a web debugging proxy tool like Fiddler (http://www.telerik.com/fiddler) or Firebug (is a Firefox extension) and take a look at the http requests to get more information on your error. You may find out that frameworks.swf is not in the location you expect.
This is just a IOError event triggered by Adobe Flash. Most likely the file just isn't found. Check your path and make sure you place the .swf file in your bin-debug directory if you're doing this from within Adobe Flash Builder

Can't find image exported from AIR app on Android phone

I feel as if I'm missing something very basic here. I'm trying to add an option to let export images from an Android app in PNG format. The code seems to work fine on my Droid Bionic and doesn't error out, but afterwards I can't find the image anywhere in the phone's storage. Where is it going? Is it possible to access images exported from an AIR app? Am I missing something completely obvious?
bdToSave.draw(screenshot);
var arrBytes:ByteArray = PNGEncoder.encode(bdToSave);
var file:File = File.desktopDirectory.resolvePath("testimage.png");
var fileStream:FileStream = new FileStream();
try {
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(arrBytes);
fileStream.close();
}
catch (errObject:Error) {
Env.outBox.text = "Error writing image file!"
}
I've also used the CameraRoll class to successfully export images and found the resulting files easily, but the images there seemed to use bad JPEG compression. So I was hoping using FileStream instead would result in nicer images.
File.desktopDirectory does not exist on Android. Use File.applicationDirectory or File.applicationStorageDirectory to write to the internal disk. You almost always want to use applicationStorageDirectory and I believe that is actually the only one you can use on iOS for writing data. For writing to external drives, and this is untested on my part, I believe you want to use File.documentsDirectory. Trace out File.documentsDirectory.nativePath to verify that is the correct path.
It might be wise to consider that the majority of higher-end phones being released now do not contain SD cards. If this is meant to be a mass market product, I'd recommend using applicationStorageDirectory instead.

Using RequestURL to get to a different folder

I am using AS3 to make a game. I use RequestURL( filename ) to obtain the music I want to play. However, this means the music file has to be in the same folder as the .fla file. How can I use it to get a music file from a different folder? I don't really like having to leave my music outside of a Music folder or properly organised somehow....
EDIT: Should have mentioned this earlier. I tried to use simply something such as "whatever/filename", but I got this security error:
SecurityError: Error #2000: No active security context.
Why?
Have you tried using the flash.media.Sound.load() method yet?
//Make a new sound object
var s:Sound = new Sound();
//Load it
s.load(new URLRequest("someDifferentMusicFolder/loop.mp3"));
//Play it
s.play()
If you are loading it via another method, such as URLLoader + URLRequest, please post your code and we should be able to help a little better.
Generally speaking though URLRequests should allow you to specify different folders, so your problem may not be in the methodology you are using but may be in your implementation? Perhaps you are getting a security error? Whatever it may be, if you post your code we can help you narrow it down.

write/save xml in as3

I want to create a stand alone pure flash application with external xml loading from the same dir. In that i want to update/overwirite my xml nodes and save it internally at run time (I dont want to go for fileReference class to save/overWrite my xml). when I load my apps next time it will react based on the updated xml.
I dont want go for AIR as it requires installation at end user side.
I cant use any server side script.
Is it possible in flash AS3.0?
Please suggest any possible solution.
Thanks..
it's possible with FileReference.save()
here is an example saving .txt files
var file:File = File.userDirectory.resolvePath("test.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTFBytes("text to save");
fileStream.close();
last time I tried this worked without any prompt as to where to save . . . if it helps anyone.
(above worked with mobile devices saving to SDcard) - you will need to allow (WRITE_EXTERNAL_STORAGE) permission.
You can't access files in Flash without AIR and FileReference, but you can save data in SharedObject. This is analogous to cookies in browser (but not tied to one). Data will be saved somewhere in "C:\Users\UserName\Application Data\Macromedia\Flash Player\" directory (example for Win7) until user clears it or available disk size is exceeded.

How can I make Air remember the location of last opened file?

All the walkthroughs I've seen specify either desktop, local files as the initial view when calling browseForOpen.
Is there a way to have the air application remember the last location a file was loaded from and default back there?
If necessary I suppose the path could be written to the local db, but even still, I do not know how to get the filepath of the loaded file.
You can use File.nativePath and File.resolvePath.
A few years later, perhaps, but thought this might help someone in the future.
var file:File = new File();
file.browseForOpen("Open");
This will open the last location.