====== Sample : Capturing Events ====== This example documents how you can capture events. What basically happens is we : * Wait for startup * Attach event listeners * Handle the events ===== Sample Setup =====
| You need to upgrade your Flash Player. |
this.publicInterfaceLoaded = function()
{
// ...
}
We wait for the flash component to start, so we know when the public interface is ready.
==== Add Event Listeners ====
When the flash component has started (in the ''publicInterfaceLoaded()'' function) we add some event listeners :
this.publicInterfaceLoaded = function()
{
var ofm = document.getElementById("ofm");
ofm.addEventListener("loadedNewView", "newView");
ofm.addEventListener("activeModeChanged", "newMode");
}
^ Event ^ Function to notify ^
| loadNewView | "newView" |
| activeModeChanged | "newMode" |
A listing of all available modes can be [[flashmap:publicinterface:modes|found here]].
A listing of all events van be found FIXME.
var ofm;
this.newView = function() {
addToListing("[view] loaded");
}
this.newMeasure = function() {
addToListing("[measure] : "+ ofm.getMeasurementsCount() +" measurements");
}
this.newMode = function(mode) {
addToListing("[mode] "+ mode);
if (mode=="measure" && listeningToMeasure==false) {
ofm.addEventListener("measurementsChanged", "newMeasure");
listeningToMeasure = true;
}
}
this.addToListing = function(message)
{
var events = document.getElementById("eventListing");
events.innerHTML += message +"
";
}
These functions are the event handlers for the events we specified (view, mode and measure).