eventDispatcher in an mxml component ?

Peter's Avatar

Peter

15 Mar, 2011 03:30 AM

Hi all,
I'm wanting to dispatch an event from a combobox change event.
i.e

public function change():void {

        var sce:StudentChosenEvent = new StudentChosenEvent(StudentChosenEvent.STUD_CH_EVT_DISPATCHED);
            eventDispatcher.dispatchEvent(sce);
    }

but this mxml component has no idea about the eventDispatcher. Whats the easiest way around this as I have my listeners setup in mediators ready to catch this event.

Thanks,
Peter

  1. 1 Posted by Peter on 15 Mar, 2011 03:40 AM

    Peter's Avatar

    I was just thinking about this some more...I guess an option would be to just update the model (as that is injected into the mxml component) then dispatch the event from there ??

  2. 2 Posted by Peter on 15 Mar, 2011 06:46 AM

    Peter's Avatar

    nope that doesnt seem to work...always get a null reference when the change event references the model which is injected into this mxml component...any ideas ?

  3. Support Staff 3 Posted by Stray on 15 Mar, 2011 11:15 AM

    Stray's Avatar

    Hi there, the normal approach would be to mediate this component and then use that mediator to catch the event from the component (or its containing parent) and then re-dispatch it to the whole framework.

    Stray

  4. 4 Posted by Peter on 15 Mar, 2011 12:06 PM

    Peter's Avatar

    Yes - I just plain forgot about this..so in my example with a simple combobox on the stage, I created a combo mediator, and in the onRegister() function I added

    eventMap.mapListener(cap, mx.events.ListEvent.CHANGE, combo_change);

    where cap is

    [Inject] public var cap:ComboAddParticipant; // my combobox

    and combo_change is this:

    public function combo_change(ev:mx.events.ListEvent):void {

            svm.participant_to_add = cap.selectedItem;
        }
    

    where svm is my model object for the application.

    Then I can reference the selected Item from the combobox anywhere by looking at the model...it works..does this sound right ??

  5. 5 Posted by stephenadams1 on 15 Mar, 2011 12:21 PM

    stephenadams1's Avatar

    Hi,

    Sounds right to me, I keep forgetting to use mediators for all of the visual components on my page. Usually I have one mediator for the page, which now I don't think is good practice.

    Your approach looks good.

    Stephen

  6. Stray closed this discussion on 29 Apr, 2011 06:05 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac