Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hi everyone,
I'm creating an Eyewear project in ThingWorx Studio and I see there are some Application Events that can be fired with a gesture.
I read in the help page of Vuforia (here: https://help.vuforia.io/studio/index.html#page/ThingWorx_Studio_Help_Center%2FEyewearExperiences.html%23) that Application Events can be bound to a service to complete actions like playing a sequence, but I see that there's the "JS" button and a textarea like in the click event for a 2D button for example.
I tried to call a function there, but in the preview mode nothing happens. (I didn't test with HoloLens because I don't have HoloLens yet)
Is there the possibility to call a JS function or it's ONLY for binding service?
Thanks,
Alessio
Solved! Go to Solution.
I found the solution.
Create a function in the JS editor like this:
$scope.app.test = function() {
//do something
}
and bind it in the JS field of the application event like this:
app.test()
This is different from the standard use of JS functions, because to bind a JS function on a click event (for example), we have to create a JS function WITHOUT the word "app", like this:
$scope.test = function() {
//do something
}
and bind it in the JS field of the click event like this:
test()
I found the solution.
Create a function in the JS editor like this:
$scope.app.test = function() {
//do something
}
and bind it in the JS field of the application event like this:
app.test()
This is different from the standard use of JS functions, because to bind a JS function on a click event (for example), we have to create a JS function WITHOUT the word "app", like this:
$scope.test = function() {
//do something
}
and bind it in the JS field of the click event like this:
test()
Hello Alessio,
Once you clicked on the JS panel near events definition like Click you can write there your own code or call the function, which you defined in the yourViewName.js. Be aware that you should use Angular functions with the proper syntax, i.e.:
$scope.view.wdg['model-1'].scale = 1;
It is the same if you are working with in the youViewName.js file.
$scope.foo = function(){
$scope.view.wdg['model-1'].scale = 1;
}
Then, in JS block you can just call your function by foo();
Regards,
Adam
Hi Adam,
please check my self response before yours.
I tried to do how you wrote, but it seems that for an Application Event (like "swipeup" or "hold") the call foo() isn't correct.
For this particular event, we have to declare in the .js file the function like this:
$scope.app.foo = function() {
......
}
and call it like this:
app.foo()
As an alternative, I found that the following approach also works:
Define the function in the JS panel in the usual way:
$scope.foo = function() {
...
}
and in the Application event JS field, call it this way:
viewCtrl.foo();