I am trying to access data obtained from an event listener function in init() in another function in an aframe component. I have tried to use binding so that the data obtained in the event listener can be bound to "this" space.
Here is my code
AFRAME.registerComponent('move', {
schema: {
},
init: function() {
this.el.sceneEl.addEventListener('gameStarted', testfun.bind(this), {once:
true});
function testfun(e){
this.speed = e.detail.source;
console.log(this.speed); // I get proper values here
}
console.log(this.speed); // value is not updated and I only get "undefined"
},
tick: function(t, dt) {
console.log(this.speed); // I get undefined
}
});
I thought if I bind this to function, I can access the data outside the even listener scope as well. Could you please spare a little time to help me figure this out?