The Extension class provides information about and access to extension packages. Many times bitmap or text resources need to be loaded from the extension package to be displayed in the user interface of the extension. This class facilitates this functionality.
// assuming an extension file with a picture called "mountains.jpg"
// and a script file called "main.js", the following should demonstrate
// loading bitmap and text resources
class MyForm extends Form {
// the bitmap is passed in rather than loaded here, because its size
// determines the arguments to super() -- and a derived constructor
// cannot bail out before calling super()
constructor(bmp) {
const width = bmp.getWidth();
const height = bmp.getHeight();
super("Startup Picture", 1, 1, width - 20, height);
this.center();
const picture = new PictureBox(0, 0, width, height - 70);
picture.setImage(bmp);
this.add(picture);
const button = new Button("Show Source", 5, height - 65, 80, 24);
button.click.connect(this, this.onShowSource);
this.add(button);
}
onShowSource() {
alert(Extension.getTextResource("main.js"));
}
}
const bmp = Extension.getBitmapResource("mountains.jpg");
if (!bmp) {
alert("mountains.jpg is missing from the extension.");
} else {
const f = new MyForm(bmp);
f.show();
Application.run();
} A valid string upon success, null otherwise
Loads a binary resource from an extension package. If the extension is packaged up into a kxt/zip file, the resource is loaded from that archive. If the extension is not packaged up, but is rather one or more non-packaged files in a directory, the resource is loaded from that directory.
A valid bitmap object upon success, null otherwise
Loads a bitmap resource from an extension package. If the extension is packaged up into a kxt/zip file, the resource is loaded from that archive. If the extension is not packaged up, but is rather one or more non-packaged files in a directory, the resource is loaded from that directory.
A valid string upon success, null otherwise
Loads a text resource from an extension package. If the extension is packaged up into a kxt/zip file, the resource is loaded from that archive. If the extension is not packaged up, but is rather one or more non-packaged files in a directory, the resource is loaded from that directory.
True if the program is running from an extension package, false otherwise
Calling this method allows the caller to determine if the program running is running in from a context of an extension package.