插件加载时如何触发事件 [英] How to fire events when plugin is loaded

查看:177
本文介绍了插件加载时如何触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的插件中,一旦加载插件,我需要启动事件。

我不想使用内置机制(将它添加到对象参数中)因为我需要能够控制与事件触发一起发送的参数。

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.

问题是当我尝试在 onPluginReady 它只是不起火..在调试时,我注意到 m_proxies 是空的(在$ code> JSAPIImpl中: :FireEvent ),但是如果我尝试使用相同的代码来触发 onMouseDown 方法中的事件,那么它的工作正常。

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.

这是我的createJSAPI代码:

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;
}

这是onPluginReady代码:

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;
}

为什么这样?

谢谢。

推荐答案

onPluginReady很可能在您的param标签的onLoad回调被调用之前被调用;这意味着您的事件处理程序尚未附加。这就是FireBreath提供onload param回调的原因 - 它为您提供了一个附加事件处理程序的地方,并发现事情已加载。

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.

编辑以澄清来自评论:

回调将提供一个参数,其中包含对您的根JSAPI对象的引用。请注意,在这种情况下,它不是对象或嵌入标记,只是JSAPI对象,因此您可以使用任何方法或属性。

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.

这篇关于插件加载时如何触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆