How to fire events when plugin is loaded

女生的网名这么多〃 提交于 2019-12-11 19:33:42

问题


In my plugin I need to be able to fire event(s) once the plugin was loaded.
I don't want to use the built in mechanism (adding it in the object params) since I need to be able to control the parameters which are sent along with the event firing.

The problem is that when I try to fire the event in onPluginReady it just doesn't fire.. While debugging I noticed that the m_proxies is empty (in JSAPIImpl::FireEvent), but if I try the same code for firing the event in the onMouseDown method then it works well.

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?

Thanks.


回答1:


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.

Edit to clarify from comments:

The callback will be provided with a single parameter which contains a reference to your root JSAPI object. Note that in this case it is not the object or embed tag, just the JSAPI object, so you can use any methods or properties from there.



来源:https://stackoverflow.com/questions/18854788/how-to-fire-events-when-plugin-is-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!