Hi,
We can use DispatchEvent to communicate events from movie clips to the main timeline. This is how I would do it.
In the main timeline, add:
Change
Code:
var score:Number = 0;
to
Code:
var scorenum:Number = 0;
As it is bad to name the variable the same as the movie clip.
Add this to the main timeline.
Code:
function addScore(e:Event):void {
scorenum +=1;
score.text = (scorenum.toString());
}
Change
Code:
function addMonsters(event:TimerEvent):void
{
var monster:MovieClip;
monster = new Monster;
monster.x = Math.random() * stage.stageWidth;
monster.y = Math.random() * stage.stageHeight;
monsterHolder.addChild(monster);
}
to
Code:
function addMonsters(event:TimerEvent):void
{
var monster:MovieClip;
monster = new Monster;
monster.x = Math.random() * stage.stageWidth;
monster.y = Math.random() * stage.stageHeight;
monster.addEventListener("my event", addScore);
monsterHolder.addChild(monster);
}
Now go into the monster movie clip
Change
Code:
function removeMonster(event:MotionEvent):void
{
this_animator.removeEventListener(MotionEvent.MOTION_END, damage);
this.parent.removeChild(this);
}
to
Code:
function removeMonster(event:MotionEvent):void
{
this_animator.removeEventListener(MotionEvent.MOTION_END, damage);
this.parent.removeChild(this);
dispatchEvent(new Event("my event"));
}
Works for me
P.S. - You have some 1009's in that code, in this.parent.removeChild(this). Good luck with that.