creator中object-c调用js遇到问题

如题:
我在creator中用object-c调用js方法提示找不到类,求大神指点!!具体代码如下:

js类代码:
var HelloWorld = cc.Class({
“extends”: cc.Component,
name: “HelloWorld”,
properties: {
label: {
“default”: null,
type: cc.Label
},
text: ‘Hello, World!’
},
statics: {
staticNode: null,
testCall: function testCall(str) {
HelloWorld.staticNode.label.string = str;
}
},
onLoad: function onLoad() {
this.label.string = this.text;
HelloWorld.staticNode = this;
},
update: function update(dt) {}
});

object代码:
ScriptingCore::getInstance()->evalString(“HelloWorld.testCall(‘testxxxx’)”);

错误提示为:
ScriptingCore::evalString:1:ReferenceError: HelloWorld is not defined

不知道creator要怎么写才能成功调用呢???????求大神出现~~~~

你在什么时机下调用的?可是sc->runScript("main.js")之后?

是的,js肯定已经初始化了,场景都已经显示出来了。我是在场景正常显示以后,定时器2秒,通过js调用oc方法,在oc方法里在回调js方法的,js调用oc方法已经正常,但是oc回调js出了上面说的问题。

在 Creator 中这样做无效的原因是我们使用 browserify 去打包,所以所有的 component 脚本都会被匿名函数包裹起来,保证不会污染全局变量,也就是说,HelloWorld 只是一个局部变量。

如果想要设置一个全局的 HelloWorld,需要这样做:

window.HelloWorld = …

多谢,多谢!!

Hi, panda,能說得詳細一d嗎?我是菜鳥:cry: