0

Using minko, "html overlay" feature, is it possible to send events to c++ code from html?

The example provided, with the framework clearly demonstrate how to send events from c++ towards html (by incrementing a counter and having it reflect in html), is it possible to have the communication the other way around?

4

1 回答 1

1

是的。

HTML DOM 事件被包装并作为 C++ 信号提供。因此,您可以执行以下操作:

dom->getElementById("my-element-id")->onclick()->connect(
  [](dom::AbstractDOMMouseEvent::Ptr event)
  {
    // do something...
  }
);

它实际上是在同一个例子中完成的:https ://github.com/aerys/minko/blob/master/example/html-overlay/src/Main.cpp#L110

您还可以使用AbstractDOM::sendMessage()C++ 中的方法或Minko.sendMessage()JS 中的函数两种方式发送和接收“消息”。您可以使用AbstractDOM::onmessage()C++ 和Minko.addEventListener("message", yourCallbackFunction).

请注意,您还可以调用AbstractDOM::eval()C++ 代码来执行 JavaScript 代码。这就是我们实际实施大部分事情的方式。

于 2015-03-08T19:39:41.193 回答