The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 3 of 3

Thread: Custom event listener works once, then not again

  1. #1
    tpann's Avatar
    275
    posts
    Instructional Designer

    Custom event listener works once, then not again

    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
    PHP Code:
    public class TutorialEvent extends Event {
         public static const 
    DISABLE_BTN:String "disableBtn";
         ...
         public var 
    params:Object;
         public function 
    TutorialEvent(type:Stringparams:Object null) {
              if (
    type == DISABLE_BTNtrace("TutorialEvent " type);
              
    super(type);
              
    this.params params;
         }
         public 
    override function clone():Event {
              return new 
    TutorialEvent(typethis.params);
         }

    Manager class
    PHP Code:
    function newTutorial() {
         
    tutorial = new Tutorial();
         
    tutorial.addEventListener(TutorialEvent.DISABLE_BTNdisableBtn);
    }
    function 
    disableBtn(t:TutorialEvent) {
         
    trace("Manager.disableBtn, t.params.action = " t.params.action);
         if (
    t.params.action == "disable"button.disable();

    Tutorial class
    PHP Code:
    ...
         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:

    Tutorial.step20: dispatching DISABLE_BTN
    TutorialEvent disableBtn
    Manager.disableBtn, t.params.action = disable


    ...which is correct, and the button gets disabled. The NEXT time and all subsequent times I start the tutorial, here's the trace:

    Tutorial.step20: dispatching DISABLE_BTN
    TutorialEvent disableBtn


    ...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.
    t i m

  2. #2
    Are you using the same tutorial/manager instance(s)? My best guess is somehow an old one is being used or a new one is getting created when it shouldn't or something happens somewhere making it so you're not dealing with the same instances you thought were

  3. #3
    tpann's Avatar
    275
    posts
    Instructional Designer
    This did occur to me Senocular, after I posted. The other times something like this has happened, after I tore half of my hair out I suddenly realized that maybe the event is getting dispatched before the listener gets created. I think that's what's probably happening because yes, it's a new instance of Tutorial. Probably a couple of additional well placed traces will be revealing.
    t i m

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012