We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Did We Break ExternalInterface with v2.0?

Home Forums Programming Did We Break ExternalInterface with v2.0?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2382
    jem
    Customer

    Hi,
    I have been experimenting with driving a scene from an external call in v2.0 of Verge3D. Something has changed.

    In earlier versions, the app was registered to the window as v3dApp.
    There was a line in the player code that reads:
    window.v3dApp = app;
    This is not present v2.0

    The v3dApp object was a convenient way to access the ExternalInterface namespace from outside of the scene.

    I don’t see a way of accessing the app or ExternalInterface with the standard code template.

    I can edit the template and add window.v3dApp, but am I missing something? Is there a new way to deal with external calls in v2.0?
    Thanks,
    Jem

    Jeremy Wernick

    #2385

    Hi,
    Yes, v3dApp is no longer there, but you should be able to use the app object itself in the code like in the “External Call” demo:

    
    function runCode() {
        // add your code here, e.g. console.log('Hello, World!');
    
        // Run a Puzzles procedure 
        app.ExternalInterface.openCover('green');
    
        // Register a Puzzles-to-Code callback
        app.ExternalInterface.myJSFunction = function(a, b, c) {
            console.log(a, b, c)
        };
    }
    

    This won’t work when accessing from the browser console though. For this you can add window.v3dApp to the template like it was before.

    Co-founder and lead developer at Soft8Soft.

    #2528
    jem
    Customer

    I was using v3dApp as a communication channel between the V3D scene and the page that holds the iFrame. I my scenario, both the parent web page and the child iframe are served from the same domain, so the v3dApp object is a simple communications channel.

    I did edit my code and added window.v3dApp. It works well. Could this, or something like this, be added back to the core template code? I could be useful, but easy to forget if it is missing.

    V3DPlayer.prototype = Object.assign(Object.create(v3d.AppPuzzles.prototype), {
    
        constructor: V3DPlayer,
    
        onLoadFinished: function(sceneLoaded, logicLoaded, editorLoaded) {
            if (sceneLoaded) {
                this.run();
                initFullScreen();
                window.v3dApp = app;
                runCode();
            }
        },
    
    });

    Thank you. Great work!
    -jem

    Jeremy Wernick

    #2535

    Yeah, I think I understand the problem. For an application which loads different scenes in an iframe it’s needed to ensure that every V3D scene is accessible from the outside, which may be inconvenient.

    The main rationale behind this decision was to eliminate confusion in case of multiple applications running on the same page, because then window.v3dApp would refer to only one of them.

    We’ll think about returning it back, maybe in the form of a more consistent solution, than it was before.

    Co-founder and lead developer at Soft8Soft.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.