im making a simple space invader game which has 2 classes called bullet and monsters.
I have a function in the main time line that adds an instance of the bullet class each time the mouse is clicked. There is also a function that adds an instance of the monster class every 3 seconds.
in the bullet class… i have this snippet of code:
if (this.hitTestObject(monster)== true)
{
addEventListener("enemyHit", testDispatcher);
dispatchEvent(new Event("enemyHit"));
}
the testDispatcher just traces a text so i know that the class is dispatching the event properly
in the monster class, i have this snippet of code:
this.addEventListener(“enemyHit”, removeMonster);
the removeMonster is just parent.removeChild(this);
So what happens is… the dispatchEvent works in the bullet class only… the maintimeline and the instances of the monster class seems to not receive the enemyHit event… How should i do it so that the monster class can listen for the enemyHit event dispatched by the bullet?