3 Replies Latest reply on Sep 1, 2017 10:31 AM by atenti RSS
    atenti Newbie

    Bind a Javascript function to an Application Event

    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

      • Re: Bind a Javascript function to an Application Event
        atenti Newbie

        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()

        • Re: Bind a Javascript function to an Application Event
          Adam Macierzyński Explorer

          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