• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to make a symbol listen to a custom event?

New Here ,
Mar 25, 2022 Mar 25, 2022

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? 

TOPICS
How to

Views

134

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 25, 2022 Mar 25, 2022

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

Votes

Translate

Translate
Community Expert ,
Mar 25, 2022 Mar 25, 2022

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines