• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it possible?

Guest
Jun 24, 2012 Jun 24, 2012

Copy link to clipboard

Copied

Hi everyone,

im a beginer with flash pro so please be gently

I got a project in mind and I wanna know if it is possible or not.

I have 4 label in my project.

First Label got 2 text box (Date.text and Name.text)

Second label got 2 text box too( Adress.text and Reason.text)

Third label got 3 text box (Calltime.text, Arrivedtime.text and Leavingtime.text)

Fourth label got 1 text box called «Details.text»

I also have a Button named Savebutton (Viewable on he four label).

What I want is, When I press on the «Savebutton», I want flash to create a new .txt document in a certain folder on my computer. I also want it to name that document with the First textbox of my project (in this case, «Date.text») but also put this textbox in the «.txt» document.

So, when i'll open my «23june2012.txt» file, I'll see something like that:

Date:23june2012

Name:Bill
Adress:8765 Old street
Reason:Car accident
Calltime:17:05

Arrivedtime:17:50

Leavingtime:20:37

Details:A blue honda Civic 2010  ''364 VCG'' crashed on a Red Mazda 3 ''321 JHK''.

So I juste wanna know if we can create this kind of things with Flash - Actionscript 3.

Thanks a lot

Bambi

TOPICS
ActionScript

Views

3.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 25, 2012 Jun 25, 2012

Copy link to clipboard

Copied

No one knows? Cmon Kglad or Ned Murphy! I know that you guys can answer this one easily

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

You can try the below code. It works for me....

import flash.events.MouseEvent;
import flash.net.FileFilter;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;

Save.addEventListener(MouseEvent.CLICK,saveDetails);


function saveDetails(e:MouseEvent):void
{
var file:File = File.applicationStorageDirectory.resolvePath(Date.text.replace(/^\s+|\s+$/g, "")+".txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
var str:String = "Date:"+Date.text +"\n"+ "Name:"+Name.text +"\n"+ "Address:"+Address.text +"\n"+ "Reason:"+Reason.text +"\n"+ "Calltime:"+Calltime.text +"\n"+ "Arrivedtime:"+Arrivedtime.text +"\n"+ "Leavingtime:"+Leavingtime.text +"\n"+ "Details:"+Details.text;
trace(str.replace("\\n","\n"));
stream.writeUTFBytes(str);
stream.close();
}

I took the textfields names as you mentioned. (.txt file is saved in local store of the program file. Program file location will be dependent on the storage directory you gave.)

Here I took applicationStorageDirectory for storing a file. You can store your file in different directories. For that once you check File class in adobe. You can get the total logic. And one more thing is when using File in your program you should set the publish settings to air.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

Thanks bhargavi reddy,

ill try it as soon as I can and ill tell you if it works fine for me too

Thanks again

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

Well, maybe it can work but im too noob with flash to make it work...When I copy paste your code, I get 13 error lol...And actually, I have no freaking idea of what are these errors and how to fix it... juste to let you know, on my ''Action keyframe'' (the one where we put the codes), I only have your script that your just gave me... nothing else... Am I suposed to create some variables or something else? Well... Here's my entire code

Retour.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_retour);

function fl_ClickToGoToAndStopAtFrame_retour7(event:MouseEvent):void

{

    gotoAndStop(1);

}

import flash.events.MouseEvent;

import flash.net.FileFilter;

import flash.filesystem.File;

import flash.filesystem.FileStream;

import flash.filesystem.FileMode;

Save.addEventListener(MouseEvent.CLICK,saveDetails);

function saveDetails(e:MouseEvent):void

{

var file:File = File.applicationStorageDirectory.resolvePath(Date.replace(/^\s+| \s+$/g, "")+".txt");

var stream:FileStream = new FileStream();

stream.open(file, FileMode.WRITE);

var str:String = "Date:"+Date.text +"\n"+ "Name:"+Name.text +"\n"+ "Address:"+Address.text +"\n"+ "Reason:"+Reason.text +"\n"+ "Calltime:"+Calltime.text +"\n"+ "Arrivedtime:"+Arrivedtime.text +"\n"+ "Leavingtime:"+Leavingtime.text +"\n"+ "Details:"+Details.text;

trace(str.replace("\\n","\n"));

stream.writeUTFBytes(str);

stream.close();

}

So, any idea of what's wrong lol? :S  If it's too complicated, just say so and ill let it go lol. Ho and by the way, I made an error in my description, the names I gave you aren't textbox named Date.text but only the Label name of my text box and they are called ''Date'' only, no .text after it....Maybe that's the problem? Well, thanks for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

Yes You have to create some user interface for my code.

First create some labels and textfields as follows

Untitled.png

Go to stage and click on the text tool. In properties select the type as static text and make all those labels as in the above screen. Now again select text tool and select input text as the type and give instance name for each text field as I mentioned in the code (for example, for the textfield beside the Date label should be named as Date like that)  and under character properties, select show border around text. Then take button component and drag it to the stage. Give the instance name as Save and in properties change the label as Save. Now your user interface is completed.

I used Date.text in code means Date is the instance name of the textfield and Date.text is the text you entered in the textbox. Text fields names should be matched with the code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 26, 2012 Jun 26, 2012

Copy link to clipboard

Copied

You can also use FileReference to save the file in your system.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 27, 2012 Jun 27, 2012

Copy link to clipboard

Copied

Damn, it wasn't on Adobe Air publication... Now it kind of work but still get this error when i press the ''Save'' button,,

Error: Error #2038: File I/O Error.

    at flash.filesystem::FileStream/open()

    at Textsavingtest_fla::MainTimeline/saveDetails()[Textsavingtest_fla.MainTimeline::frame1:16]

Any idea of what it is?

And another thing, Why can't I use any number in my textfields and some letter are missing too... The only letter I can use are the follow one (acdeilnoprstuv)

Second thing, how to chose Exactly where to put my .txt files? In exemple, I want to pu it in this location ''C:\Users\P-O\Desktop\Text test'', how to do it?

By the way, tnx alot for your help, I was giving up but now i'll do it to the end

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 01, 2012 Jul 01, 2012

Copy link to clipboard

Copied

You should select "Use Device Fonts" property from anti-alias dropdown list which is under Character in properties of textbox. So that you will be able to enter all chars.

Using FileReference you can put .txt file in your mentioned location. Use save method for FileReference instance, once search it in google (filereference in as3). You can understand how to use it.

Use FileReference instead of FileStream as follows:

import flash.events.MouseEvent;
import flash.net.FileFilter;
import flash.filesystem.File;
import flash.net.FileReference;

Save.addEventListener(MouseEvent.CLICK,saveDetails);


function saveDetails(e:MouseEvent):void
{
var file:FileReference = new FileReference();


var str:String = "Date:"+Date.text +"\n"+ "Name:"+Name.text +"\n"+ "Address:"+Address.text +"\n"+ "Reason:"+Reason.text +"\n"+ "Calltime:"+Calltime.text +"\n"+ "Arrivedtime:"+Arrivedtime.text +"\n"+ "Leavingtime:"+Leavingtime.text +"\n"+ "Details:"+Details.text;
str.replace("\\n","\n");

file.save(str,Date.text.replace(/^\s+| \s+$/g, "")+".txt");
}

I am not practically check this one. First understand FileReference and try this one. If there are any mistakes in my code you can find those easily.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 02, 2012 Jul 02, 2012

Copy link to clipboard

Copied

Ok, I'll search for it and i'll try to understand, i'll give you feedback later Tnx again

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 04, 2012 Jul 04, 2012

Copy link to clipboard

Copied

Hey! Well, actually I made some research and learn a littlebit about Filereference and now I understand how it works (basically)

So now, with this script, I can save things onto a textfile but I still got a little problem. The only way to save things is if I dont put anything in ''Date'' textfield... As soon as I put something, I cant save... it's telling me:

Error: Error #2087: The FileReference.download() file name contains prohibited characters.

    at flash.net::FileReference/_save()

    at flash.net::FileReference/save()

    at Textsavingtest_fla::MainTimeline/saveDetails()[Textsavingtest_fla.MainTimeline::frame1:16]

So I know that the problem is on this line

file.save(str,Date.text.replace(/^\s+| \s+$/g, "")+".txt");

I dont realy know what it is suposed to do But I guess that this is the code that Put the file name as ''Date'' and add a ''.txt'' after the title... Because, when I save something, I have to choose a name for the file and I have to manually add ''.txt'' after the name.. So do you know where's the problem? Maybe a code problem.. Well, still trying to understand what this line''file.save(str,Date.text.replace(/^\s+| \s+$/g, "")+".txt");'' is suposed to do but whit your help, it's gonna be faster. Thanks again, and after this one, I wont have any other question Well.. I guess Thank's

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 04, 2012 Jul 04, 2012

Copy link to clipboard

Copied

Well, didn't found what's the problem but I Cutteed it

That was my old code '' file.save(str,Date.text.replace(/^\s+| \s+$/g, "")+".txt"); '' and replaced it with this one ''file.save(str);''.. Dont really know why but actually, I can write in Datetextfield so it's not a problem anymore... That thing is that i have to manually put my file name and add a ''.txt'' after it but, it's better than nothing

So, I thank you very much and I hope i wasn't too anoying Thanks again for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 04, 2012 Jul 04, 2012

Copy link to clipboard

Copied

file.save(str,Date.text.replace(/^\s+| \s+$/g, "")+".txt");

I will explain this line.

str is the data that you want to save in a file. Date is the instance name of the date textfield. Date.text is the text that you given in the date text field i.e., date. You want to save your file with the naem of date right? So that I took the text given in the datefield to set the title for file. First check whether you give the instance name of particular textfield as Date or not. If so change that one.

Here I used replace function to trim the right and left side spaces in the string i.e, in date. And I concat .txt extension for saving the file as txt file.

If you give the date as 3july2012. The above line should be

file.save(str,3july2012.txt);

As per the syntax 1st argument is the data and 2nd argument is the filename.

Simply I am using string functions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

It still doesn't work but it's ok, I'll manually put the filename and the ''.txt'' after it. Because, if i put this code (file.save(str,Date.text.replace+".txt");), it put the name ''function Function() {}'' and it save in .txt file but as soon as I change the name, the program doesn't save it in .txt file... so I have to manually put it so it's the same thing as the first option...  Well, Great tnx to you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

file.save(str,Date.text.replace(/^\s+| \s+$/g, "")+".txt");

If it's not working, and giving you that odd file name with function in it, you might try breaking out that inner code to remove it from inside the save method like so:

var fName:String = Date.text.replace(/^\s+| \s+$/g, "")+".txt";

file.save(str, fName);



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

Thanks for you help too But it still giving me this error when i press the save button

Error: Error #2087: The FileReference.download() file name contains prohibited characters.

at flash.net::FileReference/_save()

    at flash.net::FileReference/save()

    at Textsavingtest_fla::MainTimeline/saveDetails()[Textsavingtest_fla.

It's the samething with the original code... I really dont know what I am doing wrong...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

I also checked it. But no use. I too get the same error. I didn't find the solution. I hope i will be back with solution or atleast help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 05, 2012 Jul 05, 2012

Copy link to clipboard

Copied

LATEST

Once check behaviour property under paragraph of textfield. It must be single line. All are working fine but it doesn't detect \n. I am unable to find the reason. For that I put "," instead of "\n" in str.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines