Page 1 of 1

Save/Load User Inputs from Scripted GUI in ExtendScript

Posted: July 7th, 2013, 10:03 pm
by AndyTroz
I've created a very simple GUI in ExtendScript and I'd like to know how to save and load any user inputs from the "edittext" boxes that I've created.

Code: Select all

//GUI Design
var myWin = new Window ("palette", "EditTextTest", undefined);
myWin.orientation = "row";

var groupOne = myWin.add("group", undefined, "GroupOne");
groupOne.orientation = "column";
groupOne.add("statictext", undefined, "Player 01 Name");
var etOne = groupOne.add("edittext", undefined, "");
etOne .characters = 10;
groupOne.add("statictext", undefined, "Player 02 Name");
var etTwo = groupOne.add("edittext", undefined, "");
etTwo .characters = 10;
groupOne.add("statictext", undefined, "Player 03 Name");
var etThree = groupOne.add("edittext", undefined, "");
etThree .characters = 10;
groupOne.add("statictext", undefined, "Player 04 Name");
var etFour = groupOne.add("edittext", undefined, "");
etFour .characters = 10;
groupOne.add("statictext", undefined, "Player 05 Name");
var etFive = groupOne.add("edittext", undefined, "");
etFive .characters = 10;

myWin.center();
myWin.show();

Re: Save/Load User Inputs from Scripted GUI in ExtendScript

Posted: July 8th, 2013, 5:25 am
by beginUndoGroup
Hello,
there is nothing to do: the text content is an attribute of the text container.
You can set it from within the script exactly as you set the characters attribute
(for instance etOne.text = 'Mario' sets the text to Mario). If the user changes the text input the text attribute is changed accordingly.
You can also force a specific format.
For instance:
etOne.onChange = function(){this.text = this.text.toUpperCase();}
or
etOne.onChange = function(){this.text = isNaN(parseFloat(this.text)) ? 100 : parseFloat(this.text);}

If all text containers have the same behaviour, you'd better define a single function:
function format(){this.text = this.text.toUpperCase();}
and then define
etOne.onChange = etTwo.onChange = etThree.onChange = etFour.onChange = format;