Hi, jem
The main difference between prepareExternalInterface and runCode is that the first is called before scene loading and hence initialization of the Puzzles logic, and the last – is called after:
…
prepareExternalInterface()
…
// scene loading, initializaton/execution of the Puzzles logic code
…
runCode()
…
The code of the Puzzles logic can access app.ExternalInterface and call user-defined js functions, so they should already be registered by the time of the call, otherwise it will crash. To be sure that it will work properly you should register them in prepareExternalInterface.
The crash didn’t always happen when using the “call JS function” puzzle block, but in certain configurations it did. For example, let’s say you have the following logic setup:
In this setup the JS functions are executed immediately upon the logic initialization, that is before runCode, where they usually have been registered. This led to a crash, that’s why we introduced a special place like prepareExternalInterface to avoid such problems.
On the other hand you can define a function via the puzzle block “when called from JS”:
and call it from the application code like this:
...
app.ExternalInterface.myFunc();
...
Considering the execution order, mentioned above you should call it in runCode, after it was created during the Puzzles initialization.
So, basically, you need to register JS callbacks in prepareExternalInterface and do other stuff in runCode.
Attachments:
You must be
logged in to view attached files.
Co-founder and lead developer at Soft8Soft.