I have a class Manager that instantiates Tutorial. Tutorial dispatches events back up to Manager telling Manager to disable certain aspects of Manager at appropriate times. Specifically, Tutorial dispatches TutorialEvent.DISABLE_BTN to disable a button during the duration of the tutorial.
I’m finding that the first time Tutorial dispatches DISABLE_BTN it works just fine, but after that it doesn’t. Here are the highlights:
TutorialEvent
public class TutorialEvent extends Event {
public static const DISABLE_BTN:String = "disableBtn";
...
public var params:Object;
public function TutorialEvent(type:String, params:Object = null) {
if (type == DISABLE_BTN) trace("TutorialEvent " + type);
super(type);
this.params = params;
}
public override function clone():Event {
return new TutorialEvent(type, this.params);
}
}
Manager class
function newTutorial() {
tutorial = new Tutorial();
tutorial.addEventListener(TutorialEvent.DISABLE_BTN, disableBtn);
}
function disableBtn(t:TutorialEvent) {
trace("Manager.disableBtn, t.params.action = " + t.params.action);
if (t.params.action == "disable") button.disable();
}
Tutorial class
...
function step20():void {
trace("Tutorial.step20: dispatching DISABLE_BTN");
dispatchEvent(new TutorialEvent(TutorialEvent.DISABLE_BTN, {action:disable}));
}
...
When I start the tutorial the first time, here’s the trace I get:
[FONT=courier new]Tutorial.step20: dispatching DISABLE_BTN
TutorialEvent disableBtn
Manager.disableBtn, t.params.action = disable[/FONT]
…which is correct, and the button gets disabled. The NEXT time and all subsequent times I start the tutorial, here’s the trace:
[FONT=courier new]Tutorial.step20: dispatching DISABLE_BTN
TutorialEvent disableBtn[/FONT]
…and of course the button is not being disabled. I am not removing the DISABLE_BTN listener at any point in Manager, and clearly the event is being dispatched. So why is disableBtn() listener not firing??
I should mention that TutorialEvent has over 70 types and up to this point I have had no problem with any of them.