ssEvents Overview

ssEvents is a _global object that sends notifications to multiple listeners for any number of SWF Studio events. You use this object similar to other built-in Flash objects, such as Mouse or Key, whereby you create an object that contains functions with the name of the events you want to be notified about. You then add that object as a listener to the Mouse or Key object. This is the approach for events in SWF Studio. Rather than writing a setNotify yourself, you add a listener object to ssEvents for a particular command and event.

Using ssEvents rather than setNotify has a couple of benefits worth noting:

  1. Have multiple objects listen to the same event.
  2. Listen to multiple events on the same object.

The events are normally specified in the setNotify method of the command objects, e.g. Mouse.setNotify contains 3 events: onMouseMove, onMouseButton, and onMouseWheel. The event parameter takes the command object plus the event name as a value. For more information on any event, look at the setNotify method of the command object. Example: Mouse.onMouseMove originates from the onMouseMove notification of Mouse.setNotify.

Follow one of these links for more information on the notifications you can receive:


Examples:

Example 1:
With this example we monitor the progress of pages being loaded into the embedded Browser. The data is only being written to a textfield, but could easily be applied to a progress bar.

var myListener_obj = new Object();
myListener_obj.onProgress = function (event_obj)
{
    // For this example we will write the progress value to a textfield on _root.
    var v = event_obj.result.split(',');
    _root.progress_txt.text = v[0] + ' of ' + v[1] + ' bytes';
}
ssEvents.addEventListener({listener:myListener_obj,event:'Browser.onProgress'});

Example 2:
This is a similar example to the one above, only here we will have multiple objects listening to the same event. This is useful when creating large projects where it is good to have different parts of the project be able to act independently.

var myListener_obj = new Object();
myListener_obj.onProgress = function (event_obj)
{
    // Here we will write the progress value to a textfield on _root.
    var results_array = event_obj.result.split(',');
    var kLoaded_int = Math.round(results_array[0]/1024);
    var kTotal_int = Math.round(results_array[1]/1024);
    _root.progress_txt.text = kLoaded_int + 'KB of ' + kTotal_int + ' KB';
}
ssEvents.addEventListener({listener:myListener_obj,event:'Browser.onProgress'});

// This code would be inside a progress bar component:
this.pbListener_obj = new Object();
this.pbListener_obj.onProgress = function (event_obj)
{
    // Here we will change the scaling of a rectangle (where this.pb_mc is a MovieClip) so it appears as a progress bar display.
    this.pb_mc._xscale = Math.round((event_obj.result.split(',')[0] / event_obj.result.split(',')[1]) * 100);
}
ssEvents.addEventListener({listener:this.pbListener_obj,event:'Browser.onProgress'});

Example 3:
In this example we set up a listener to listen for the onQuit event. Doing this means we can take action when the user tries to exit the program. Here we save some data to a SharedObject and then call the method to really quit the application. Notice that we specify a callback function that will receive the event rather than a function named after the event.

var myListener_obj = new Object();
myListener_obj.saveThenQuit = function (event_obj)
{
    // Save the data to a SharedObject then force the application to quit.
    _root.myData_so.data.lastResponse = _root.lastResponse_txt.text;
    ssCore.App.forceQuit();
}
ssEvents.addEventListener({listener:myListener_obj,event:'App.onQuit',callback:'saveThenQuit'});