Copy link to clipboard
Copied
Hello,
I am attempting to make a project that has a button on it, and when it is clicked I have a custom event that is defined in the main stage dispatched. Then, I have a listener inside of a symbol that I would like to be fired when the custom event in the main stage is dispatched. Currently, the symbol is not listening to the event and I am unsure how to fix it.
Here is the code in my main stage:
var fireBounceBallBind = fireBounceBall.bind(this);
this.button.addEventListener('click', fireBounceBallBind);
var bounceBall = new createjs.Event('bounceBall');
function fireBounceBall(evt) {
this.dispatchEvent(bounceBall);
}
And here is the code in my symbol:
var eventListenerBind = eventListener.bind(this);
var bounceBallBind = bounceBall.bind(this);
this.addEventListener('bounceBall', eventListenerBind);
function eventListener(evt) {
this.addEventListener('tick', bounceBall);
}
function bounceBall(evt) {
// bounce ball logic here
}
Is there a way to have the symbol listen to my custom 'bounceBall' event, or must I create this logic inside of the main stage?
i see the same problem with creating an event, but using correct code to test.
just use a string. that works but you'll need to use a listener in the same scope as the dispatcher. eg,
on main timeline:
this.s.dispatchEvent("BB");
on instance s timeline:
this.addEventListener("BB", f.bind(this));
or:
on main timeline:
this.dispatchEvent("BB");
on any child of the main timeline:
this.parent.addEventListener("BB",etc
Copy link to clipboard
Copied
i see the same problem with creating an event, but using correct code to test.
just use a string. that works but you'll need to use a listener in the same scope as the dispatcher. eg,
on main timeline:
this.s.dispatchEvent("BB");
on instance s timeline:
this.addEventListener("BB", f.bind(this));
or:
on main timeline:
this.dispatchEvent("BB");
on any child of the main timeline:
this.parent.addEventListener("BB",etc