Masth0/ScratchCard

Promise after init()

Closed this issue · 1 comments

This promise didn't resolve and the addEventListener didn't work properly

// Init
sc.init().then(() => {
  sc.canvas.addEventListener('scratch.move', () => {
    let percent = sc.getPercent().toFixed(2)
    console.log(percent)
  })
}).catch((error) => {
  // image not loaded
  alert(error.message);
});

Except if I put the addEventListener alone, out from the promise:

  sc.canvas.addEventListener('scratch.move', () => {
    let percent = sc.getPercent().toFixed(2)
    console.log(percent)
  })

never mind, sorry