Skip to main content

Callbacks

The optional JavaScript callback functions enables developers to react on events fired by FSI Image Twins.

Refer to the appropriate chapter to learn how to implement callbacks.

The following callback functions can be used:

onCardUncovered​

onCardUncovered()
Called when one card is uncovered.

instance.addListener('onCardUncovered', () => {
// one card uncovered
doReallyGoodThings()
})
Example

onCardsCovered​

onCardsCovered()
Called when all cards are covered.

instance.addListener('onCardsCovered', () => {
// all cards covered
doReallyGoodThings()
})
Example

onCardsUncovered​

onCardsUncovered()
Called when all cards are uncovered.

instance.addListener('onCardsUncovered', () => {
// all cards uncovered
doReallyGoodThings()
})
Example

onDestroy​

onDestroy()
Called as soon as the viewer is destroyed.

instance.addListener('onDestroy', () => {
// instance is destroyed
doReallyGoodThings()
})
Example

onGameEnd​

onGameEnd(stats)
Called once after the game is finished.

stats
object
Game statistics
instance.addListener('onGameEnd', (stats) => {
// game is finished
myFunc(stats)
})
Example

onGameStart​

onGameStart(totalCards)
Called once after all cards have appeared.

totalCards
integer
the total amount of cards used
instance.addListener('onGameStart', (totalCards) => {
// all cards have appeared
myFunc(totalCards)
})
Example

onInit​

onInit(parameters)
Called as soon as the viewer is initialized.

parameters
object
parameters as object
instance.addListener('onInit', (parameters) => {
// viewer initialized
myFunc(parameters)
})
Example

onPairFound​

onPairFound(stats, byChance)
Called each time a matching pair is found.

stats
object
Game statistics
byChance
boolean
Shows if match was made by chance, i.e. a lucky match
instance.addListener('onPairFound', (stats, byChance) => {
// game is finished
myFunc(stats, byChance)
})
Example

onSkinChanged​

onSkinChanged(currentSkin, beforeSkin)
Called when the skin is changed.

currentSkin
string
Currently used skin
beforeSkin
string
Skin used beforehand
instance.addListener('onSkinChanged', (currentSkin, beforeSkin) => {
// skin is changed
myFunc(currentSkin, beforeSkin)
})
Example