Developer Resources

Creating a Simple Form

With scripting, you can do many different things; but often, you’ll define an interface that let’s you enter information.  To create a basic form interface, create a new script, then enter the following in the script:

var f = new Form;       // create a new form;               // show the form;      // process events

Essentially, this script says:

  1. Create a new form.
  2. Show the form.
  3. Run the application, processing any events the user may perform on the form.

Once you’ve saved the script, go ahead and run it.  As you can see, it opens a new form.

While simple, this script demonstrates the three basic steps to create a new interface with a form:  create the form, show it, and process events on it.

We can easily extend this example to show a custom form.  To customize the form, create a custom form, then show the custom form in the same way:

var f = new MyForm;     // create a new custom form; // show the custom form; // process the events

// define the custom form as follows
class MyForm extends Form
function MyForm()
// when the form is first created, add a new button
this.add(new Button("Ok"));

This script says:

  1. Create a new custom form of type MyForm.
  2. Show the custom form.
  3. Run the application, processing any events the user may perform on the form.
  4. Define MyForm as follows:  use the Form type as a starting point, but when it’s created, add a button to it with the text “Ok”.

While this script is nearly as simple as the first script, it introduces one important concept, which we’ll discuss more below:  you can define your own data types from scratch, or from pre-existing data types.  When you define a new data type in this way, you are creating a “class”, and when you are creating this class from another data type, you are “extending” the other class.

In the above example, the class MyForm is a new data type that derives its characteristics from another class called Form.  When MyForm is created, the MyForm() function inside the MyForm class runs, creating a button that is added to the form.