JS module

09 June 2016 12:30
I couldn't resist opening the 2000 topic in the Newbies Question section
So my question is can i create my own modules in JS so that the functions i need to call in Blander could also be called in the web page, from out of the canvas?

I call a function from my app that opens a div on top of my app by removing a class ( with display none). But once the div is open i can't call the function that opened it… It's Undefined in the context of the div.

So is the scope off the JS file private to the canvas where the seen is loaded ?

I was thinking that i might write another JS file and import it as a module in the main JS file created by the project manager and thereby i could probably import it in the HTML file via another JS file that would import it to?

Does that make sense?
10 June 2016 19:29
I call a function from my app that opens a div on top of my app by removing a class ( with display none). But once the div is open i can't call the function that opened it… It's Undefined in the context of the div.
This is strange, the function should work.

So is the scope off the JS file private to the canvas where the seen is loaded ?
If your function is undefined, then there might be a scope issue, but it can't be related to a canvas or to some other html element. You should check the scope where this function is defined and the scope where you're trying to use it. If you have no idea what's wrong, show the code, so I can take a look on it.

I was thinking that i might write another JS file and import it as a module in the main JS file created by the project manager and thereby i could probably import it in the HTML file via another JS file that would import it to?
Yes, you can separate your code into different modules if you want. Just load it in the HTML file via <script> and import it in the app via the require method.
10 June 2016 23:00
I think it might all be stuck in the scope of the b4w.register("LukeVideoLowPoly", function(exports, require) {….
I will try the module require as soon as i can. Thanks for the answer!
 
Please register or log in to leave a reply.