Reputation: 5
I'm not really very good with Actionscript 3.0 and I was wondering how I can save variables to a file (A .txt), as well as set variables using a button.
What I am trying to do is get a name, date and another name. I have 3 input boxes and I am unsure how to get the text input to be saved into a text file. I need it to create a new file every time it saves so the details of each user is saved (This is my task, it's an induction thingy, nothing bad).
Also, I am unsure how to set variables with the click of a button. Say the button instance name is "next_button" and I want to get it to set a variable that I can call later on. If I click it, the variable will be set to "Contractor", that's what I need.
The start of the "quiz" if you would call it is asking for the name, date and the company they're from. I need those details to be saved to a file.
I also need help with getting a variable to be set with the click of a button. I have 4 buttons on the screen and I want to get the button to change a variable to "Permanent Employee" or "Contractor".
Any help is appreciated.
Upvotes: 0
Views: 516
Reputation: 1302
To save data using the FileReference Class:
var data:String = "JDLKJFSDKJFHS";
var file:FileReference = new FileReference();
file.save(data,"filepath.txt");
To set a variable on mouse click:
var saveVar:String = "";
var buttons:Array = [button1,button2,button3];
var buttonStrings:Array = ["Contractor","Employee","Slave"];
button.addEventListener(MouseEvent.CLICK,onClick);
function onClick(e:MouseEvent):void{
var index:int = buttons.indexOf(e.target);
if (index > 0) saveVar = buttonStrings[index];
}
Upvotes: 1