header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Nick
Points:0
Posts:0

1/5/2012 3:45:08 PM

Title: Create files to specific folder does not work


I use this sample to create 2 files to store several variables. The first is some variedles from an xml file to another and the other is a text file to store several values
It works when I test the movie in Flash, but when I run the swf file on my system the methods below don't create the file.

this is the code used:

save_btn.addEventListener(MouseEvent.CLICK, saveGame);
function saveGame(event:MouseEvent):void
{
	function saveQuestionFile():void
	{
               loadQuestions.splice(0,loadQuestions.length);
		var questionFile:File = File.desktopDirectory;
		questionFile = questionFile.resolvePath("./FlashProCS5_CIB/Mine/Pro/savedQuestions.xml");
		trace(questionFile.url);
		for (var i:int = 0; i< questions_XML.Questions.length(); i++)
		{
			loadQuestions.push(questions_XML.Questions[i]);
		}
		//trace(loadQuestions[v]);
		var questionfileStream:FileStream = new FileStream();
		questionfileStream.open(questionFile, FileMode.WRITE);
		questionfileStream.writeUTFBytes("<QuestionsList>");
		questionfileStream.writeUTFBytes(loadQuestions.toString());
		questionfileStream.writeUTFBytes("</QuestionsList>");
		//questionfileStream.addEventListener(Event.CLOSE, fileQuestionClosed);
		questionfileStream.close();

		function fileQuestionClosed(event:Event):void
		{
			trace("closed event fired");
		}
	}
	function saveTextFile():void
	{
		var file:File = File.desktopDirectory;
		file = file.resolvePath("./FlashProCS5_CIB/Mine/Pro/savedGame.txt");
		trace(file.url);
		this.x = 131;
		var fileStream:FileStream = new FileStream();
		fileStream.open(file, FileMode.WRITE);
		fileStream.writeUTFBytes(g + "\n" + points +"\n" + g2 + "\n" + points2 + "\n" + footClip1.rotation + "\n" + footClip2.rotation + "\n" + v + "\n" + p + "\n" + p1_txt.text  + "\n" + p2_txt.text + "\n" + footClip1.x + "\n" + footClip1.y + "\n" + footClip2.x + "\n" + footClip2.y);
		//fileStream.addEventListener(Event.CLOSE, fileClosed);
		fileStream.close();

		function fileClosed(event:Event):void
		{
			trace("closed event fired");
		}
	}

	saveQuestionFile();
	saveTextFile();

}



1
Troy
Points: 730
Posts:0
1/5/2012 10:26:57 PM



SWF file cannot create files.Running inside flash it will work for testing. You should create this as AIR application and then install AIR application to make it work as desired.

2
RedBull
Points: 930
Posts:0
1/5/2012 10:37:14 PM



check this AIR tutorial to save file in any folder

http://livedocs.adobe.com/flex/3/html/help.html?content=Filesystem_15.html

you can get more information on FileStream Class from this link

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html

3
Nick
Points: 0
Posts:0
1/6/2012 12:01:25 PM



Thanks for the reply.

Installed as air application and fix the path in order to save the files in the correct file but....nothing
In the mean time motion tween written with actionscript 3 does not work in air appli although works fine in flash environment. My nerves...!!
I will try to fix this.
How?
Don't know.
If someone can help...
Thanks in advance

4
Nick
Points: 0
Posts:0
1/6/2012 7:25:50 PM



Everything is working properly. Following the advices (thank you Troy and RedBull)and experimenting with directories eventually now everything is working fine.

This is a good tutorial to help you set up an air application:
http://www.republicofcode.com/tutorials/flash/airapplication/3.php

And motion tween is working JUST FINE. I'm just an idiot that forgot to load some movie-clips in order to play correctly....
Never mind....

This is the sample of the code that is working perfect(air application):


function save():void
	{
var file:File = File.applicationStorageDirectory.resolvePath("save.txt");
		var fileStream:FileStream = new FileStream();
		fileStream.open(file, FileMode.WRITE);
		fileStream.writeUTFBytes(man.x + "n\" + man.y  + "n\" + score);

		fileStream.close();
}
	save();
Thanks again guys for the replies!!


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 0+5 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions