My Books

  • Follow me on Twitter
My Photo

Subscribe my blog

  • Get this widget from Widgetbox
  • Add to Google
  • RSS FEEDS
  • Enter your Email here to subscribe :



    Powered by FeedBlitz

Blog Widget by LinkWithin

« Passing connection-level credentials to the JMSAdapter of BlazeDS | Main | Opera Mobile 9.5 supports Flash Lite player »

Comments

Danilo Celic

It seems that with your solution and a really fast machine, you may in inadvertently end up duplicate file names if you resolve two paths within a millisecond. Not sure how much that needs to be taken into account, but it is a potential issue.

I've handled this type of situation by using a file name with an incrementing value, so in this case, snapshot1.jpg, snapshot2.jpg. To get the usable file name we would need to know if a file exists with the current increment. Not up on AIR and AS3 coding, but using a mix of the AIR API code and some JavaScript syntax, it could be something like:

fileName = "snapshot@@INCREMENT@@.jpg";
increment = 1;

while( ! File.documentsDirectory.resolvePath( fileName.replace(/@@INCREMENT@@/, increment).exists ) ){
increment++;
}

file = File.documentsDirectory.resolvePath( fileName.replace(/@@INCREMENT@@/, increment);

Seems that this could be abstracted easily into a function that takes the parent folder, a base name and the extension to use or even take just the folder path and a full file name and the function could return the full path that is incremented appropriately (even leaving off the increment if the full file name is available for use.

An issue with this might be that if you are using the async file access, then the file path may be available when you ask what file name to use, but not available when you try to write the file out. Again, not sure how big a deal this is, but want to throw that out there as a potential issue.

Marco Casario

Hey Danilo,
thank you for point it out !
It's a good point of view....

Hope to talk to you soon,
ciao

Emanuele Cipolloni

there are issues as well:

1) What happen if the application is closed and re-run
2) What happen if ther eis already a file with that name

Normally OSes provide a way to generate unique files name for a given directory, unfortunately AIR can't access such capability directrly. One possible solution is to use date and time to build file name, not sure if you can access milliseconds from the Time object.

Mauro

You could save a progressive numeric value in a LSO ("snapshot_"): so, when it's time to save, you get the current value, increment it by one, save file "embedding" the incremented value in its name. My two cents... :-)

para kazan

thank you for your articles

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment