Search code examples
apache-flexactionscript-3eventsactionscriptevent-handling

How can we listen to an event dispatched in PopUpWindow inside the parent component?


I have a warning Popwindow with 2 buttons 'Submit' and 'Cancel'. On clicking submit I invoke a function and dispatch 'submit' Event with bubble true. I want to handle this inside my parent application. I have already registered the event with the parent container as well as the popup instance.

Inside Parent.mxml :


private function launchWarningPopUp():void {
        var win:Warning = PopUpManager.createPopUp(this, Warning, false ) as Warning; 
        win.addEventListener(SubmitQuizEvent.SUBMIT_QUIZ, submissionDone);
        this.addEventListener(SubmitQuizEvent.SUBMIT_QUIZ, submissionDone);
        PopUpManager.centerPopUp(win);
}

private function submissionDone():void{
   Alert.show('Inside SubmissionDoneTwo');
}

Inside Warning.mxml:

private function submitHanlder():void {
            dispatchEvent(new SubmitQuizEvent(SubmitQuizEvent.SUBMIT_QUIZ,true));
            PopUpManager.removePopUp(this);
}

The event should bubble to Parent.mxml. Am I doing something wrong here or is it simply not possible ?

I am stuck here, any help in this regard would be greatly appreciated. Thanks in advance.


Solution

  • I was unable to catch this event inside my function as the signature was missing. After I add this the code worked.

    private function submissionDone(event:SubmitQuizEvent):void{
    
                Alert.show('Inside SubmissionDone with signature');
    }
    

    =================================================================================

    I am facing another issue now. The event is captured only when I use ' win.addEventListener....' and not with 'this.addEventListener ............'.This is surprizing to me.

    If Parent.mxml is parent of 'win' then the events triggered inside 'win' should bubble and should be caught by the parent. This is not happening.

    Is 'win' not considered child of the Parent.mxml ? And is treated as external component ?

    Please let me know your view on this ??