Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Desktop, Mobile and non-browser Environments > AIR (Apollo)

Reply
 
Thread Tools Rate Thread Display Modes
Old 01-11-2008, 02:26 PM   #1
eliddell
Senior Member
 
eliddell's Avatar
 
Join Date: Sep 2006
Location: boston
Posts: 250
Send a message via AIM to eliddell
Default re-writing to an existing text file from AIR

i am trying to write text to an existing text file in the same folder as my air app..

ActionScript Code:
import flash.filesystem.File; import flash.filesystem.FileStream; import flash.filesystem.FileMode; var docDir:File = File.documentsDirectory; var dskTopFileStream:FileStream = new FileStream(); var fileString:String = docDir.nativePath; var dskTopFile:File = File.documentsDirectory;     dskTopFile = dskTopFile.resolvePath(fileString+"test.txt"); dskTopFileStream.openAsync (dskTopFile, FileMode.UPDATE); dskTopFileStream.writeUTFBytes ("Hello World!"); dskTopFileStream.close ();

the code doesnt do anything to the file
eliddell is offline   Reply With Quote
Old 01-11-2008, 02:33 PM   #2
xwielder
Senior Member
 
Join Date: Aug 2007
Location: NE Ohio
Posts: 524
Send a message via AIM to xwielder
Default

ActionScript Code:
dskTopFile = dskTopFile.resolvePath(fileString+"test.txt"); trace(fileString); trace(fileString + "test.txt"); dskTopFileStream.openAsync (dskTopFile, FileMode.UPDATE);

Run those traces and let me know what you come up with. I think you might need to do this:

dskTopFile = dskTopFile.resolvePath(fileString+"\test.txt");

But I'm not sure.
xwielder is offline   Reply With Quote
Old 01-11-2008, 02:47 PM   #3
eliddell
Senior Member
 
eliddell's Avatar
 
Join Date: Sep 2006
Location: boston
Posts: 250
Send a message via AIM to eliddell
Default

traces don't seem to work at all
eliddell is offline   Reply With Quote
Old 01-11-2008, 02:49 PM   #4
xwielder
Senior Member
 
Join Date: Aug 2007
Location: NE Ohio
Posts: 524
Send a message via AIM to xwielder
Default

Yeah... I'm working on it. Gimme a minute.
xwielder is offline   Reply With Quote
Old 01-11-2008, 02:51 PM   #5
xwielder
Senior Member
 
Join Date: Aug 2007
Location: NE Ohio
Posts: 524
Send a message via AIM to xwielder
Default

Well,.. actually, "trace" will work, but you have to go into debug mode to see your traces when working with AIR files. Basically, instead of hitting CTRL+Enter to test your movie, just use CRTL+SHIFT+Enter. You'll see your traces then.
xwielder is offline   Reply With Quote
Old 01-11-2008, 02:56 PM   #6
eliddell
Senior Member
 
eliddell's Avatar
 
Join Date: Sep 2006
Location: boston
Posts: 250
Send a message via AIM to eliddell
Default hmmm

weird.. i couldn't get the trace to work so i created a dynamic text field that was my fileString variable... found the file!!!! but thats not where i wanted it.. it is going to the My Documents folder.. while my actual air file is in in the programs/writeTest folder.. i wanted the file to be in the same folder as the AIR file.. ho do i do that?


Erik
eliddell is offline   Reply With Quote
Old 01-11-2008, 02:57 PM   #7
xwielder
Senior Member
 
Join Date: Aug 2007
Location: NE Ohio
Posts: 524
Send a message via AIM to xwielder
Default

I got this to work:

ActionScript Code:
import flash.filesystem.File; import flash.filesystem.FileStream; import flash.filesystem.FileMode; var docDir:File = File.documentsDirectory; var dskTopFileStream:FileStream = new FileStream(); var fileString:String = (docDir.nativePath + "\\test.txt"); var dskTopFile:File = File.documentsDirectory; dskTopFile = dskTopFile.resolvePath(fileString); dskTopFileStream.openAsync (dskTopFile, FileMode.WRITE); dskTopFileStream.writeUTFBytes ("Hello World!"); dskTopFileStream.close (); trace(fileString);
xwielder is offline   Reply With Quote
Old 01-11-2008, 03:02 PM   #8
xwielder
Senior Member
 
Join Date: Aug 2007
Location: NE Ohio
Posts: 524
Send a message via AIM to xwielder
Default

Quote:
Originally Posted by eliddell View Post
...i wanted the file to be in the same folder as the AIR file.. ho do i do that?

Change
ActionScript Code:
var docDir:File = File.documentsDirectory;

to:
ActionScript Code:
var docDir:File = File.applicationResourceDirectory;
xwielder is offline   Reply With Quote
Old 01-11-2008, 03:07 PM   #9
xwielder
Senior Member
 
Join Date: Aug 2007
Location: NE Ohio
Posts: 524
Send a message via AIM to xwielder
Default

You may find this link quite useful for making AIR apps. I personally reference it on a daily basis.

http://www.actionscriptcheatsheet.co...cheatsheet.pdf
xwielder is offline   Reply With Quote
Old 01-11-2008, 03:08 PM   #10
eliddell
Senior Member
 
eliddell's Avatar
 
Join Date: Sep 2006
Location: boston
Posts: 250
Send a message via AIM to eliddell
Default

that gives me an error...

1119: Access of possibly undefined property applicationResourceDirectory through a reference with static type Class.
eliddell is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing to text file theMonitor Flash 8 General Questions 6 10-05-2006 04:40 PM
External text loads partially & Render text as HTML prevents loading of text file piercedwater ActionScript 2.0 20 03-03-2005 12:33 AM
PLEASE HELP: using html tags 2 load image into text file sineadhartley ActionScript 2.0 11 05-15-2004 01:56 PM
Writing to a text file using actionscript sharadha ActionScript 1.0 (and below) 1 08-01-2002 08:08 AM
help writing to a text file seniorcrap Other Flash General Questions 4 04-05-2002 06:04 AM


All times are GMT. The time now is 09:53 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.