Skip to content

Instantly share code, notes, and snippets.

@fwextensions
Created May 7, 2012 22:36
Show Gist options
  • Save fwextensions/2631084 to your computer and use it in GitHub Desktop.
Save fwextensions/2631084 to your computer and use it in GitHub Desktop.
Code for listening to FW events
private const SupportedFWEvents:Object = {
onFwActiveDocumentChange: 1,
onFwActiveSelectionChange: 1,
onFwActiveToolChange: 1,
...
};
private function onPreinitialize() : void
{
// we need to register these callbacks early in the startup process.
// registering them from applicationComplete is too late.
if (ExternalInterface.available) {
ExternalInterface.addCallback("IsFwCallbackInstalled",
onIsFwCallbackInstalled);
// create a handler for all the supported events. we don't know yet
// which events the JSML will actually listen for, but we have to
// create the handlers now. otherwise, we'll never get the events.
for (var eventName in SupportedFWEvents) {
ExternalInterface.addCallback(eventName,
createFWEventHandler(eventName));
}
}
}
private function onIsFwCallbackInstalled(
inFunctionName:String) : Boolean
{
return (inFunctionName in SupportedFWEvents);
}
private function createFWEventHandler(
inEventName:String) : Function
{
return function()
{
//console.log("method", inEventName);
// only pass the event to the panel if it's actually listening
// for it, to avoid the overhead of passing data to the JS side.
// switching documents triggers 4 events, so they can add up.
if (inEventName in registeredFWEvents) {
onAppJSEvent({ type: inEventName });
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment