Hi,
I'm trying to make a very simple Address/Phone Book.
So, I tried making a tryout one before I do the real thing.
I made
two Input Text Boxes (one for 'name' and the other for phone).
I then added
one Button.
Idea: The idea is that when I click the button, whatever is typed in the name and phone input boxes will be saved in a .txt file.
Here is my code:
ActionScript Code:
done_btn.addEventListener(MouseEvent.CLICK, saveIt);
var dataArray:Array = new Array();
var dataFR:FileReference = new FileReference();
function saveIt(e:MouseEvent):void
{
dataArray = [{name:name_txt.text,phone:phone_txt.text}];
tFR.save(dataArray[0].name+dataArray[0].phone,'addressbook.txt');
}
Of course, it works with no problem.
But, I want to ask if I'm doing this code the right way.
Also, is there a way where I can keep inputting data and saving it but without destroying the current data in the .txt file?
I think that I'd have to use "if statement" there. However, the tFR.save always brings out a "save as..." pop-up (after I click the button).
Thank you for any advice.
Edit:
Oh I think I will try loading the .txt file first to an Array so that when I save, I can re-write the old data then add the new data with it.