Packages and Access Modifiers
Packages allow you to structure your JavaFX files (.fx). You can put one or more source files in a directory, and then declare them to be part of a package. The directory name must be the name of the declared package.
By default, all variables, classes and class members can not be accessed from other scripts. You need to use access modifiers like public to publish them to other scripts and packages. The following script animals/bird.fx defines a package and a public class with a public property:
package animals; // declaring package
public class Bird { // public class
public var name : String; // public property
}
To access the Bird class from outside the package, you need to specify the full name:
def myBird : animals.Bird = animals.Bird { name: "Big Bird" };
Alternatively, you must import the name at the beginning of the script and can then use the short name:
import animals.Bird;
def myBird : Bird = Bird { name: "Big Bird" };
If you need several declarations from a package, you can also import them all. However, that makes it more difficult to find out where a declaration is coming from:
import animals.*;
def myBird : Bird = Bird { name: "Big Bird" };
An access modifier can be put in front of a variable, function or class to make them available outside of the current script. By default, only the current script can access them. To give other scripts additional access, the following access modifiers are available:
package var a; // all scripts in the same package have full access
protected var b; // subclasses and scripts in the same package have full access
public var c; // every script has full access
public-read var d; // all scripts can read, only the current script can write
package public-read var e; // all scripts can read,
// only scripts in the same package can write
protected public-read var f; // all scripts can read,
// only the current script can write
public-init var g; // all script can read, all can set it in object initializer,
// only scripts in the same package and subclasses can write
package public-init var h; // all script can read,
// all can set it in object initializer,
// only scripts in the same package can write
protected public-init var i; // all script can read,
// all can set it in object initializer,
// only scripts in the same package and subclasses can write

