I’ve placed listeners on the var “topic_mc” (below), but I’m not sure how to remove them properly:
private function layoutTopics(modNum:Number, attachTo:MovieClip):void {
topicLength = MainMenu.modArr[modNum].topicArr.length;
if (Interface._ui != null) {
pageLength = Interface._ui.pageArr.length;
}
for (var t:Number = 0; t<topicLength; t++) {
if (modNum == 0 && t == 0) {
//Splash page should not be on the Menu screen
} else {
topic_mc = new Topic();
attachTo.addChild(topic_mc);
topic_mc.name = "topic"+t;
topic_mc.title.text = MainMenu.modArr[modNum].topicArr[t].header;
//Special placement for module 0
if (modNum == 0) {
topic_mc.y = (topic_mc.height-1)*t+17;
} else {
topic_mc.y = (topic_mc.height-1)*t+75;
}
topic_mc.x = 12;
var topNum:Number = t+1;
topic_mc.id = getPageArrIndex(modNum, topNum);
topic_mc.moduleNumber = modNum;
topic_mc.topicNumber = topNum;
topic_mc.buttonMode = true;
topic_mc.useHandCursor = true;
topic_mc.mouseChildren = false;
topic_mc.addEventListener(MouseEvent.CLICK,loadTopic);
// ADDING A DELAY TO ALLOW TIME FOR THE "topic_mc" TO INSTANTIATE
topic_mc.addEventListener(Event.ENTER_FRAME, addDelay);
//trace(topic_mc.name);
}
function addDelay(evt:Event):void {
evt.target.removeEventListener(Event.ENTER_FRAME, addDelay);
//trace(evt.target.name);
//if available
if (previousTopicState == "complete") {
evt.target.gotoAndStop("available");
previousTopicState = "incomplete";
}
//if visited/completed
if (checkTopicComplete(modNum, topNum)) {
evt.target.gotoAndStop("completed");
previousTopicState = "complete";
} else {
//if in progress/incomplete topic
if (Interface._ui != null) {
if (evt.target.moduleNumber == Interface._ui.currentModule) {
if (evt.target.topicNumber == Interface._ui.currentTopic) {
evt.target.gotoAndStop("inProgress");
}
}
}
}
}
}
}
Using
evt.target.removeEventListener(Event.ENTER_FRAME, addDelay);
doesn’t really work - any trace statement I place within the event function will run for infinity. How do I call the objects properly to remove the listeners? Note: I’ve tried referring to currentTarget instead of target but that doesn’t make any difference.