简体   繁体   English

Pulpcore和Javascript到Java Applet的通信

[英]Pulpcore and Javascript to Java Applet communication

I have a problem using Pulpcore Java framework. 我在使用Pulpcore Java框架时遇到问题。 I tried to call Java function from JavaScript on the page with applet. 我试图用applet从页面上的JavaScript调用Java函数。 The applet is correctly embedded on the page (pulpcore generated the code). 小程序正确嵌入在页面上(pulpcore生成了代码)。 The JavaScript code is: JavaScript代码为:

$(document).ready(function() {
    var self = $("#pulpcore_object")[0];
    self.show2();
});

I even debugged this code and it gets applet from DOM correctly, but then there is this JavaScript error: 我什至调试了这段代码,并正确地从DOM获取了applet,但是然后出现了这个JavaScript错误:

Uncaught exception: TypeError: 'self.show2' is not a function 未捕获的异常:TypeError:'self.show2'不是一个函数

which makes me little confused. 这让我有点困惑。 Using 使用

document.pulpcore_object.show2();

gives the same error. 给出相同的错误。

I don't know if I'm missing something or where the problem is. 我不知道我是否缺少某些东西或问题在哪里。 I can't even find any Pulpcore tutorial showing JavaScript to applet communication. 我什至找不到任何显示JavaScript与小程序通信的Pulpcore教程。

This answer was posted by f1ames as an answer inside the question: 此答案由f1ames发布,作为问题内的答案:

This code works: 此代码有效:

$(document).ready(function() {
    var applet = $("#pulpcore_object")[0];
    var scene = applet.getCurrentScene();
    scene.method();
});

So, we get the applet and then the main scene class and now we can call any public method from the scene class. 因此,我们得到了applet,然后得到了主要的场景类,现在我们可以从场景类中调用任何公共方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM