Domanda

I've noticed that the call to the createJSAPI method in my plugin is only called after I somehow try to interact with the actual DOM element.

Is there a way to make it happen before any javascript interaction is happening? In the documentation for getRootJSAPI it states:

It is not recommended to call this from the constructor or before setHost is called, as many JSAPI objects need the BrowserHost and a weak_ptr to the Plugin class to function correctly

So when is it appropriate to call this method? in onPluginReady or onWindowAttached?

Thanks.


Edit

This is my createJSAPI code:

FB::JSAPIPtr plugin::createJSAPI()
{
    this->jsApi = JSApiPtr(new pluginAPI(FB::ptr_cast<plugin>(shared_from_this()), m_host));
    return this->jsApi;
}

And this is the onPluginReady code:

void plugin::onPluginReady()
{
    this->getRootJSAPI();
    this->jsApi->fireMyEvent(this->myId);
}

and the event isn't fired, though this does:

bool plugin::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *)
{
    this->jsApi->fireMyEvent(this->myId);
    return false;
}

Why is that?

As for the build in onload mechanism, I need my own, since I need to pass some parameters to that fired event.

Thanks.

È stato utile?

Soluzione

You can call this method during or after onPluginReady -- that's one of the main purposes of the function.

EDIT:

To answer your further question, onPluginReady is likely to be called before your onLoad callback from the param tag gets called; that means your event handlers aren't attached yet. That's the reason that FireBreath provides the onload param callback -- it gives you a place to attach event handlers and find out that things are loaded.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top