Hello guys, I have a custom typescript component like following,
@ccclass
export default class TestComp extends cc.Component
{
@property(cc.Label)
debugText : cc.Label = null;
public foo(name)
{
this.debugText.string = name;
cc.log("successfully called foo");
}
}
How can I call function foo(name)
of typescript component from AppActivity? I tried following…
Cocos2dxJavascriptJavaBridge.evalString("var controller = require('TestComp');");
But I am getting error of missing file. Can anyone tell me the right way to call TestComp.foo(name)
. Thanks.
1 Like
Hello,
I was getting the same issue before some days. I was able to solve it by using the following.
In AppActivity.java,
Cocos2dxJavascriptJavaBridge.evalString(“cc.find(‘YOUR_NODE_NAME’).getComponent(‘TestComp’).foo(‘Test Call from Java’);”);
Hope this helps you.
Cheers!
1 Like
Hey, thanks for responding.
cc.find seems to returning null node. Do I have to mark the node as persistent? Thanks.
It worked with a little change. Most of the time nodes are under Canvas so I changed it to ,
cc.find('Canvas/node_name')
Thanks a lot.
system
closed
#6
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.