How do you call functions from the root html file?

Home Forums Programming How do you call functions from the root html file?

This topic contains 11 replies, has 2 voices, and was last updated by Yuri Kovelenov Yuri Kovelenov 2 months, 3 weeks ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #7286
    tidlybit
    tidlybit
    Customer

    Hi I’ve got my my_awesome_app.html file targeted inside an iframe, and I can externally call functions if I place them on the html file itself in between <script></script> tags.

    My question is what do I place in
    function myfunction() { ? } to call the actual functions that are in the my_awesome_app.js in order to trigger events?

    Thanks.

    #7301

    Hi,

    If you’d like to call your functions from the global namespace, you can use the window namespace, something like this:

    window.myfunction = function() {}

    This declaration can be placed anywhere in the app’s js file.

    Founder & CEO at Soft8Soft
    LinkedIn | FB | Twitter | VK | 新浪微博

    #7335
    tidlybit
    tidlybit
    Customer

    Hi Yuri,
    Thanks for your reply.

    So what I’d like to trigger is this function from my visual_logic.js:

    Can I place something like this in my visual_logic.js?

    …or am I way off?

    I am able to call a myfunction() successfully if it’s on the html this way.

    Sorry, I’m an instructional designer, with limited JS but Love what you guys have done and see so much educational potential in it. It really IS amazing. -Rick

    #7336

    In this case you can use the following puzzles for interacting with your code:

    https://www.soft8soft.com/docs/#manual/introduction/Puzzles.call_JS_function
    https://www.soft8soft.com/docs/#manual/introduction/Puzzles.when_called_from_JS

    … and the functions should be registered in ExternalInterface in your app js file – see the examples by the above links

    Founder & CEO at Soft8Soft
    LinkedIn | FB | Twitter | VK | 新浪微博

    #7417
    tidlybit
    tidlybit
    Customer

    Hi Yuri,
    Thanks, I am now able to call a function from my index.html to my_function.js

    however..

    I have 2 questions:
    1. How do I call myJSCallback() from window.myfunction
    2. the runCode() seems to initially play the puzzle upon loading from line 83, is there way to prevent this?

    Attachments:
    You must be logged in to view attached files.
    #7422

    Hi,

    Just move myJSCallback to myfunction:

    Founder & CEO at Soft8Soft
    LinkedIn | FB | Twitter | VK | 新浪微博

    #7479
    tidlybit
    tidlybit
    Customer

    Thanks that’s how I thought it should work, but when I tested it I only got the alert message.

    However, when I place the function before the alert like this I don’t get the alert message either, which makes me think that it’s perhaps throwing an error.

    What’s interesting is that “app.ExternalInterface.myJSCallback()” works in runCode(app) fine.
    Thanks again Yuri for all the help. Any thoughts?

    • This reply was modified 2 months, 3 weeks ago by tidlybit tidlybit.
    #7490

    One note – myfunction must be called after a Verge3D app is initialized and a scene is loaded. You can check for errors in the browser console (shown with F12 on Windows).

    Founder & CEO at Soft8Soft
    LinkedIn | FB | Twitter | VK | 新浪微博

    #7545
    tidlybit
    tidlybit
    Customer

    So I am getting this in the console, and I’m pressing the button to make the call after the verge player loads.

    You can see it here http://www.richardleehill.com/call

    I zipped the code below too. Thanks.

    Attachments:
    You must be logged in to view attached files.
    #7547

    Sorry, my bad, here is how it should be

    Founder & CEO at Soft8Soft
    LinkedIn | FB | Twitter | VK | 新浪微博

    #7553
    tidlybit
    tidlybit
    Customer

    :yahoo: Thankyou! I’ve got it working and talking to LMS software….

    • This reply was modified 2 months, 3 weeks ago by tidlybit tidlybit.
    #7556

    :good:

    Founder & CEO at Soft8Soft
    LinkedIn | FB | Twitter | VK | 新浪微博

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.