I have declared two animations on a <a-sky>
. The first is set to activate on click
the second is triggered by another javascript file using the custom 'close' event.
I defined my sky as follows:
<a-sky mixin="sky" id="thesky" src="puydesancy.jpg" scale="1 1 -1" radius="1" >
<a-animation attribute="scale" direction="alternate" begin="click" dur="1000" easing="linear" from="1 1 -1" to="10 10 -10"></a-animation>
<a-animation attribute="scale" direction="alternate" begin="close" dur="1000" easing="linear" from="10 10 -10" to="1 1 -1"></a-animation>
</a-sky>
//This is my click handler which calls Closer()
(function () {
var skies = document.querySelectorAll('#thesky');
var i;
for (i = 0; i < skies.length; ++i) {
skies[i].addEventListener('click', function () {
console.log('click', this);
Closer();
})
}
})();
//This is in the return function of Closer()
var sphereElement = document.getElementById("thesky");
sphereElement.emit('close');
Everything runs correctly the first time through, I click on the sky object and it scales in size. The Closer method waits for a delay then shrinks the sky back to it's normal size. However, the second time I click the sky object it plays the 'close' animation instead of the 'click' animation and then once the delay has passed it plays the 'click' animation instead of the 'close'. What is causing these two animations to get fired by the wrong events on the second passthrough.