2 Replies Latest reply on Dec 13, 2006 6:07 PM by lenny2

    Custom Event Issue

    lenny2 Level 1
      Hope you flex geniuses can help me on this one....

      the issue: an action script custom event is being dispatched by one object but is not being "heard" by it's parent despite the fact that a) the child object uses the [event] declaration in it's class definition, b) the event is being correctly dispatched, and c) the parent object uses an addEventListener method to listen for the event.

      the layout:
      includes an application component (mxml) that has as it's only direct child an action script custom component called FloorPlan. On creationComplete the floor plan object instantiates an action script class called Booth as many times as is required (based on the number of booths that needs to be displayed on the floor plan) and then adds the instances to itself via addChild() method. The booth objects are based on Sprite class and so they have click events, etc. When one of the booth instances is clicked, the click event of the booth instance fires and the handler creates an instance of the ShowCompanyProfileEvent (action script class based on the Event class) and then dispatches it. The ShowCompanyProfileEvent event handler for now should just open an Alert box.

      I know the code works within the Booth class because when I register an event listener in the booth class itself and then click on a booth, the listener "hears" the dispatched event and opens the Alert box.

      The problem is that The floor plan instance has a registered event listener to listen for the dispatched custom event also but nothing happens when I click a booth instance (which like I said should dispatch the custom event). I deleted the addEventListener code in the booth class thinking that maybe it was catching it first but still it wouldn't work.

      Any ideas? I have reallysearched and searched to no avail. As I mentioned, I get no errors at all when I compile and run the code. I just don't get the expected results.

        • 1. Re: Custom Event Issue
          buabco Level 1
          LensterRAD, don't know if I got the hole idea but I guess you are listening to the ShowCompanyProfileEvent directly on the FloorPlan, something like:

          FloorPlan.addEventListener(ShowCompanyProfileEvent, someFunction);

          if this is the case, you'll probably need to add the BUBBLE parameter to the event, so it will follow the hole event propagation model.

          something like: dispatchEvent(ShowCompanyProfileEvent, true);
          • 2. Re: Custom Event Issue
            lenny2 Level 1
            I spent 4 hours trying to figure this out and it was all due to leaving off one parameter!! Thanks, buabco!