0

I've some problem in sending a simple message in overlay-example of Minko library.
I tried use the c++ code of this example without modifying it, while I add a Minko.addListener in my javascript. The code of the js is here:

<html>
   <head>
   </head>
  <body>
  <script>
      Minko.addEventListener("hello", function() {
          /* simply replace ":" with <-----> */
      document.getElementById("gameTimeLeftSeparator").textContent = "<------>"
    });
  </script>
  <body>
                <div id="content">
                        <div id="scoreBanner">
                                <div id="scoreBannerBackground"></div>
                                <div class="teamScore" id="teamScoreRed">0</div>
                                <div class="teamScore" id="teamScoreBlue">0</div>
                                <div class="gameTimeLeft" id="gameTimeLeftMn">0</div>
                                <div class="gameTimeLeft" id="gameTimeLeftSeparator">:</div>
                                <div class="gameTimeLeft" id="gameTimeLeftSec">0</div>
                        </div>
                </div>
                <body >
  </body>
</html>

I really don't understand where is the problem. I add the listener, and my very simple function (tested with a classical addListener("click", ... ) is working. Here I use Minko.addListener("hello", ... ) that is sent by c++ (line 113 of the main.cpp of that example).

Cœur
  • 37,241
  • 25
  • 195
  • 267
D.Giunchi
  • 1,900
  • 3
  • 19
  • 23

1 Answers1

1

What you're doing in your app is a very bad example of C++/JS messaging since you can implement the exact same behavior simply using the C++ DOM API like this:

overlay->mainDOM()->getElementById("gameTimeLeftSeparator")->textContent("<----->");

If what you're trying to do is simply to update a DOM element (content), then the code above (or similar C++ DOM API methods) is the way to go.

If your actual use case cannot be implemented using the C++ DOM API, please update your original question/example accordingly.

Anyway, this:

Minko.addEventListener("hello", ...

should be this of course:

Minko.addEventListener("message", ...

cf this answer

Community
  • 1
  • 1
  • My concern is not really modifying the textContent, this is a light sample for changing something. Let's suppose I need to trigger and then modify a js object using its accessors (not a dom element). I'm sure that the code you put is better, it is the same as in overlay-example, but I need another way to trigger a change, and "sendMessage" method anyway should work, or not? – D.Giunchi Mar 24 '15 at 12:51
  • As answered in your other questions (http://stackoverflow.com/questions/29206609/binding-of-a-dom-element-to-a-javascript-variable and http://stackoverflow.com/questions/29209300/sending-a-message-from-c-to-javascript/29209405?noredirect=1#comment46634159_29209405), there are many ways to "change" a JS object from C++ without using a complicated C++/JS messaging scheme. They are perfect answer for the problem as you describe it. If not - and for any answer to be remotely helpful - you should make your original question more precise and your example relevant. – Jean-Marc Le Roux Mar 24 '15 at 18:14
  • Suppose I want only to use in JS the Minko.AddListener, and bind a message (like the "hello") to my callback function, and do the sendMessage("hello") from C++. Does it work or did I miss something in the sample I just pasted in? – D.Giunchi Mar 24 '15 at 19:46
  • thanks! the last editing solve everything! I put Solved in the subject :) – D.Giunchi Mar 26 '15 at 09:07