Android callJavascript

Bodoquezorrilla

Bodoquezorrilla

I try to pass data to my ArquitectWorld in Javascript, I'm using the method callJavascript("nameFn(param)"); my code:

Android:

arquitectView.callJavascript("myFn(num)");

Javascript:

function MyFn(param) {

//here received the variable from android

}

var World = {

//here I need to use the variable that I received

};

World.init();

I received succesfully the variable, but I can't use it inside World

M

Martin Lechner

said
almost 5 years ago

Hi Sergio,

This is more of an architectural question and/or a JavaScript-related question rather than a question specifically for the Wikitude SDK.

Depending on your program structure and the way you have organized your code, there are lots of ways to achieve what you want. A straight forward (however, not necessarily beautiful and elegant) way is to add the myFn function to your World object, so you have access to all your properties in your World object. Something like:

var World = {

myFn : function(value){

// your code here

}

}

In your world, you can then call the function using arquitectView.callJavascript("World.myFn(num)");

However, as I said already, this depends heavily on the way you organize your code. A straight forward way is sometimes not the best solution.