[Flashcoders] Read and save xml file on disk

4 views
Skip to first unread message

natalia Vikhtinskaya

unread,
Feb 9, 2014, 11:53:35 AM2/9/14
to Flash Coders List
Hi to all friends
I have to create stand alone application that can read xml file then after
editing save it on the disk. I need to do that by FlashCs6. I know that
FileReference.load() : Loads data from a file selected by the user.
FileReference.save() : Saves data to a file location selected by the user.
Is it possible to save and read without the user?
What is the better way for this task?
Do you know any good tutorials with examples on this subject? This task it
new for me and I want to read about that more.

Thank you in advance.
_______________________________________________
Flashcoders mailing list
Flash...@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

John R. Sweeney Jr.

unread,
Feb 9, 2014, 1:46:38 PM2/9/14
to Flash Coders List
Hi,

I presume your building an AIR app, so look into File.applicationStorageDirectory and resolvePath. You can read and write behind the scenes without user intervention.




John R. Sweeney Jr.
Senior Interactive Multimedia Developer
OnDemand Interactive Inc
Hoffman Estates, IL 60169

da...@eyebright.com

unread,
Feb 9, 2014, 8:41:44 PM2/9/14
to flash...@chattyfig.figleaf.com
Natalia,

You can use the File (see e.g. "applicationDirectory" or "resolvePath")
and Filestream (open, read<x>, and write<x>) functions, but these are only
available if you're using Air (other wrappers like Zinc have similar
functionality). If it's an executable created by simply Publishing with
Flash Player as the target, I think security issues prevent you from doing
this.

HTH,
--Dave

> ----------------------------------------------------------------------
> From: natalia Vikhtinskaya <natav...@gmail.com>

natalia Vikhtinskaya

unread,
Feb 10, 2014, 5:55:08 AM2/10/14
to Flash Coders List
Thank you for your answers. Unfortunately I don't know AIR or Zinc. I
looked for a way to publish this application as swf file and then convert
it to exe. I did that before with games. So no way to do that without AIR
or Zinc?

David Benman

unread,
Feb 10, 2014, 6:51:40 AM2/10/14
to Flash Coders List
AIR is another publishing method available in Flash and because it creates an executable that removes many of the Flash player's security restrictions. Prior to Flash CC you could also create a Mac or Windows projector that would save a file.

I think most methods still require user interaction, but its usually not that hard to scare up some sort of user interaction to trigger the saving. The user doesn't necessarily need to choose the save location each time, just the save process needs to be triggered by a user interaction.
David Benman
Interactive Developer
da...@dbenman.com
http://www.dbenman.com
(315) 637-8487 (home office)

natalia Vikhtinskaya

unread,
Feb 10, 2014, 10:14:02 AM2/10/14
to Flash Coders List
Here how I try to save xml in the same folder where is my app

import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
import flash.events.Event;

//personnel. xml file
......

// save to disk
var appDirectory:File = File.applicationDirectory;
var newFileStream:FileStream = new FileStream();
var fileString:String = appDirectory.nativePath;
var appFile:File = File.documentsDirectory;
appFile = appFile.resolvePath(fileString+"\personnel.xml");
trace(fileString+"\personnel.xml")
it gives path myfolderpersonnel.xml instead of myfolder\personal.xml

How to solve this problem?

Jim Hayes

unread,
Feb 10, 2014, 10:26:39 AM2/10/14
to Flash Coders List
you need to escape the \ like so "\\"

appFile = appFile.resolvePath(fileString+"\\personnel.xml");
trace(fileString+"\\personnel.xml")
________________________________________
From: flashcode...@chattyfig.figleaf.com [flashcode...@chattyfig.figleaf.com] on behalf of natalia Vikhtinskaya [natav...@gmail.com]
Sent: 10 February 2014 15:14
To: Flash Coders List
Subject: Re: [Flashcoders] Read and save xml file on disk

Jim Hayes

unread,
Feb 10, 2014, 10:41:14 AM2/10/14
to Flash Coders List
Or use a / which I think works both on PC and the mac (which \ will not, that will only work on windows)
Forgive me if I'm wrong on that one.
________________________________________
From: flashcode...@chattyfig.figleaf.com [flashcode...@chattyfig.figleaf.com] on behalf of Jim Hayes [j...@primalpictures.com]
Sent: 10 February 2014 15:26
To: Flash Coders List
Subject: RE: [Flashcoders] Read and save xml file on disk

natalia Vikhtinskaya

unread,
Feb 10, 2014, 11:17:50 AM2/10/14
to Flash Coders List
Thank you! "\\' works.

Henrik Andersson

unread,
Feb 10, 2014, 11:20:19 AM2/10/14
to Flash Coders List
Just use File.separator, it will get you the correct one if you care.

Jim Hayes skriver:
> Or use a / which I think works both on PC and the mac (which \ will not, that will only work on windows)
> Forgive me if I'm wrong on that one.
> ________________________________________
> From: flashcode...@chattyfig.figleaf.com [flashcode...@chattyfig.figleaf.com] on behalf of Jim Hayes [j...@primalpictures.com]
> Sent: 10 February 2014 15:26
> To: Flash Coders List
> Subject: RE: [Flashcoders] Read and save xml file on disk
>
> you need to escape the \ like so "\\"
>
> appFile = appFile.resolvePath(fileString+"\\personnel.xml");
> trace(fileString+"\\personnel.xml")


---
Detta epostmeddelande innehåller inget virus eller annan skadlig kod för avast! antivirus är aktivt.
http://www.avast.com

Jim Hayes

unread,
Feb 10, 2014, 11:42:55 AM2/10/14
to Flash Coders List
That I never knew! Even after years of using AIR.
________________________________________
From: flashcode...@chattyfig.figleaf.com [flashcode...@chattyfig.figleaf.com] on behalf of Henrik Andersson [he...@henke37.cjb.net]
Sent: 10 February 2014 16:20
To: Flash Coders List
Subject: Re: [Flashcoders] Read and save xml file on disk
Reply all
Reply to author
Forward
0 new messages