Skip to main content
1-Visitor
July 5, 2019
Solved

Include Java Script Dokuments

  • July 5, 2019
  • 1 reply
  • 3098 views

Hi there,

is there a possibility to include .js files ? 

I need to use the function round of math.js.

 

Thanks for help.

 

Best answer by RolandRaytchev

I think the math module should be already available as part of node.js installation. When I check my Vuforia Studio installation I could find it  in folder:

C:\Users\<my_user_name>\Documents\VuforiaStudio\Projects\node_modules\three\src\math\Math.js

I think to access it you need to call some think like Math.round()

In generally it should be possible to use an external module. I think  C:\Users\<your_user_name>\Documents\VuforiaStudio\Projects\<your_projectName>\extensions  or extensions\js ... could be a good location where you can try to save the additional javaScript library file / I could remember that some time added libraries but could not find such example now. I think you must add also the path to runtimeExtensions.json file

But there is another simple way in JavaScript. So for example you can upload the javaScript file to you resource/Uploaded project directory and  load it by JavaScript e.g. :

 

//---------------START Loading the API----------------------- 
$scope.loadMyScript = function() {
 $scope.asyncLoadScript("app/resources/Uploaded/myJavaScriptFile.js")
 .then(function() { 
 console.log("myJavaScriptFile.js was loaded successfully" }, 
 function() { 
 console.log("there something went wrong""); 
 
 });
}
//---------------END Loading the API----------------------- 
 

 

1 reply

21-Topaz I
July 5, 2019

I think the math module should be already available as part of node.js installation. When I check my Vuforia Studio installation I could find it  in folder:

C:\Users\<my_user_name>\Documents\VuforiaStudio\Projects\node_modules\three\src\math\Math.js

I think to access it you need to call some think like Math.round()

In generally it should be possible to use an external module. I think  C:\Users\<your_user_name>\Documents\VuforiaStudio\Projects\<your_projectName>\extensions  or extensions\js ... could be a good location where you can try to save the additional javaScript library file / I could remember that some time added libraries but could not find such example now. I think you must add also the path to runtimeExtensions.json file

But there is another simple way in JavaScript. So for example you can upload the javaScript file to you resource/Uploaded project directory and  load it by JavaScript e.g. :

 

//---------------START Loading the API----------------------- 
$scope.loadMyScript = function() {
 $scope.asyncLoadScript("app/resources/Uploaded/myJavaScriptFile.js")
 .then(function() { 
 console.log("myJavaScriptFile.js was loaded successfully" }, 
 function() { 
 console.log("there something went wrong""); 
 
 });
}
//---------------END Loading the API----------------------- 
 

 

mn11-VisitorAuthor
1-Visitor
July 5, 2019

Hi @RolandRaytchev 

If I copy your codelines i get the error:

ionic.bundle.min.js:150 TypeError: $scope.asyncLoadScript is not a function

 

In my folder I coudn´n find math.js.

 

Thanks for help.

21-Topaz I
July 5, 2019

I am sorry , I forgot , of course, to provide the function definition:

scope.asyncLoadScript = function (fname) {
 return new Promise((resolve, reject) => {
 if(fname) {
 var head = document.head || document.getElementsByTagName('head')[0],
 script = document.createElement('script');
 script.async = true;
 script.onload = resolve;
 script.onerror = reject;
 script.type = 'text/javascript';
 script.src=fname;
 head.appendChild(script);
 }
 });
}