I have a Kotlin->JS multiplatform up and running t...
# getting-started
r
I have a Kotlin->JS multiplatform up and running to draw canvas stuff. I attempt to call
requestAnimationFrame()
Copy code
fun main() {
  requestAnimationFrame(::main)
}
but receive
Copy code
Unresolved reference: requestAnimationFrame
I have tried many combinations of imports, and all of them at once.
Copy code
import kotlinx.browser.document
import kotlinx.browser.window
import org.w3c.dom.*
import org.w3c.dom.events.*
import kotlin.browser.window
What do I need to import to get access to this standard JS function?
j
kotlinx.browser.window
is the one you need I believe
r
Well, that is in the list of imports I have at the top.. So not sure what's going on
j
You also import
kotlin.browser.window
so I'm not sure how that compiles, you should probably remove that one
r
so only
Copy code
import kotlinx.browser.document
import kotlinx.browser.window
import org.w3c.dom.*
?
because this is what I had originally before hitting the error
j
For this function specifically, you only need
import kotlinx.browser.window
(not the 2 others), but yeah maybe you need the others for the rest of your code
Wait, are you calling the function on the
window
object? Because you can't just call it directly. You need:
Copy code
window.requestAnimationFrame { ... }
r
nah I was calling it how you do in javascript
just as a globally accessibel function
ahk let me try that
j
Yeah in Kotlin the global scope and the
window
scope are not mixed up
r
yeah that worked, thanks
🎉 1