Callbacks & Methods
We support callbacks and methods for app and iframe integrations.
You can use these callbacks and methods to create more customization in your app, for example your own loading screen or a custom restart view for your game. You can also use them to save data passed back to you from the game to create custom experiences in your app, such as unlocking certain features of your apps using games.
Callbacks
Callbacks contain an interface name that you may listen to. Once the data is being sent the body of the message will contain the json data passed to your interface.
Iframe Example
<script>
window.addEventListener("message", function(event) {
switch(event.data.type) {
case "loading":
console.log("Event: Loading received: " + event.data.value);
break;
case "gameStarted":
console.log("Event: GameStarted received: " + event.data.value);
break;
case "gameOver":
console.log("Event: GameOver received: " + event.data.value);
break;
case "gameClick":
console.log("Event: gameClick received: " + event.data.value);
break;
default:
break;
}
});
</script>
Callback: Loading
If you wish to build a custom loading screen for your game you can use our callback for Loading.
When the progress value reaches 100 you are ready to hide your custom loading screen and present the game.
Example: {"loading": {"progress": value}};
Parameter |
Type |
Description |
value |
int |
Progress of your loading, 0-100. |
Callback: Game Started
When the user starts a game round the data will be passed to your app’s interface.
Example: {"gameStarted": {"state": true}};
Parameter |
Type |
Description |
state |
Bool |
State is sent as true |
Callback: Game Over
When the user completes a game round the data will be passed to your app’s interface. Save the game data as you see fit and use it to build gamified solutions within your app.
Example: {"game": {"time": time, "score": score}};
Parameter |
Type |
Description |
time |
int |
Time spent of the game round (seconds) |
score |
int |
Score of the game round |
Callback: Game Click
When the user clicks on a CTA within a game this event will be called.
Example: {"gameClick": {"state": true}};
Parameter |
Type |
Description |
state |
Bool |
State is sent as true |
Methods
Can be called from your app to trigger actions in the game.
Method: Start Game
If you wish to build your custom Start Game-button in your own restart view.
Example:
iOS Swift: yourWebView.evaluateJavascript("startGame()");
Android Java: yourWebView.loadUrl("javascript:startGame()");
Method: Game Over
If you wish to manually end a game round for the user, e.g. when the user closes or leaves your app and you wish to retrieve the game data for that current round you can manually call the endGame method.
Example:
iOS Swift: yourWebView.evaluateJavascript("gameOver()");
Android Java: yourWebView.loadUrl("javascript:gameOver()");
Method: Turn Sound On
You can set if the sound should be on or off as default on the Settings page in Flarie Studio. If you want to create your own custom restart view with sound settings in your app you can use this method to turn the sound on.
Example:
iOS Swift: yourWebView.evaluateJavascript("turnSoundOn()");
Android Java: yourWebView.loadUrl("javascript:turnSoundOn()");
Method: Turn Sound Off
You can set if the sound should be on or off as default on the Settings page in Flarie Studio. If you want to create your own custom restart view with sound settings in your app you can use this method to turn the sound off.
Example:
iOS Swift: yourWebView.evaluateJavascript("turnSoundOff()");
Android Java: yourWebView.loadUrl("javascript:turnSoundOff()");
Method: Pause Controller
You can call this method to display the pauseController. With the pauseController the user can pause the game to see game instructions and also resume or end the game round. The pauseController will automatically hide again when the game ends.
Example:
iOS Swift: yourWebView.evaluateJavascript("showPauseController()");Android Java: yourWebView.loadUrl("javascript:showPauseController()");