My apologies in advance… it’s another ‘Removing event listeners’ thread.
I have the following code, adding monsters to the stage:
stage.addEventListener(Event.ENTER_FRAME, mainLoop);
function mainLoop(Event):void {
if(Math.random()*100 < 1) {
generateMonster();
}
}
// --
function generateMonster():void {
var newMonster:Monster = new Monster();
// [Set 'Monster' properties such as x and y values]
addChild(newMonster);
newMonster.addEventListener(Event.ENTER_FRAME, monsterLoop);
}
// --
function monsterLoop(Event):void {
// [Move monster around stage]
if(Event.target.hitTestObject(hero)) {
// Remove monster and listener:
var target:DisplayObject = Event.target as DisplayObject;
target.removeEventListener(Event.ENTER_FRAME, monsterLoop);
target.parent.removeChild(target);
}
}
However, as I’m sure those of you who know what’s going wrong have guessed, this results in the error message “ReferenceError: Error #1069: Property ENTER_FRAME not found on flash.events.Event and there is no default value. at test_fla::MainTimeline/monsterLoop()”
I am blanking on a solution to this at the moment - could anyone help?