System

The System namespace contains global convenience functions.

static function System.log(any value...)

Output the supplied arguments to the Zing log.

static function System.openUrl(Url url)

Open the provided URL in the system browser.

static function System.getSetting(String key) → String

static function System.saveSetting(String key, String value)

Zing settings are a very simple, persistent key-value data store. You set a value using the saveSetting() method, and can retrieve it using the getSetting() method.

Settings is not well optimized for handling string values larger than a few kilobytes, so should not be used to store huge blobs of data.

static function System.broadcastMessage(Json message)

Send a broadcast message.

Broadcast messages provide a simple, local message passing system for use in your Zing prototype. Broadcast messages can be used to communicate between different parts of your Zing code, or to communicate between your Zing code and native application code.

Broadcast messages are sent like this,

function sendMessage() {
    var message = {
        type: "beginLogin",
        username: "snuffaluffagus"
    }
    System.broadcastMessage(message)
}

and received by defining an event handler like this,

Item {
    // ... code ...
}

on System.broadcastMessage(message) {
    System.log("The message was:" , message)
}

All broadcast event handlers are called for every message sent, even those defined in the element sending the message. Consequently, it is helpful to have some form of "type" field in the message to disambiguate them.

To learn more about sending and receiving broadcast messages from native code, refer to the documentation inside the "broadcastMessageReceived" callback in the sample code generated when exporting your prototype.