Is there some event that is triggered when A-Frame is fully loaded? Right now I’ve managed to get my document.querySelector(".a-enter-vr-button")
working, but only after placing it inside a setTimeout
function, which seems a bit of a makeshift solution. So if anyone has any way of making a js script fire after A-Frame has fully loaded please let me know!
Asked
Active
Viewed 8,829 times
9

ngokevin
- 12,980
- 2
- 38
- 84
1 Answers
20
You can use the loaded
event:
document.querySelector('a-scene').addEventListener('loaded', function () {...})
But we recommend using components so you don't have to handle waiting on events for things to get set up:
AFRAME.registerComponent('log', {
schema: {type: 'string'},
init: function () {
var stringToLog = this.data;
console.log(stringToLog);
}
});
Then to use the component from HTML:
<a-scene log="Hello, Scene!">
<a-box log="Hello, Box!"></a-box>
</a-scene>

ngokevin
- 12,980
- 2
- 38
- 84
-
1also see other related events and associated docs: https://aframe.io/docs/1.3.0/core/scene.html – Kyle Baker Sep 22 '22 at 21:46