Home › Forums › Programming › Did We Break ExternalInterface with v2.0?
- This topic has 3 replies, 2 voices, and was last updated 6 years, 9 months ago by Ivan Lyubovnikov.
-
AuthorPosts
-
2018-02-25 at 9:18 pm #2382jemCustomer
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.0The 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,
JemJeremy Wernick
2018-02-26 at 8:06 am #2385Ivan LyubovnikovStaffHi,
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.
2018-02-26 at 8:45 pm #2528jemCustomerI 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!
-jemJeremy Wernick
2018-02-27 at 9:28 am #2535Ivan LyubovnikovStaffYeah, 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.
-
AuthorPosts
- You must be logged in to reply to this topic.