Call a function in Popup's parent??

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default Call a function in Popup's parent??

    I have a popup window component called from one of my other components. It
    needs to call a function in the parent component.

    I tried:

    <mx:Form width="100%" id="saveForm">
    <mx:FormItem label="Name" width="100%" fontWeight="bold">
    <mx:TextInput id="saveName" width="100%" textAlign="left"
    fontWeight="normal" text="{fileName}"/>
    </mx:FormItem>
    <mx:HBox id="buttons" width="100%">
    <mx:Spacer width="100%"/>
    <mx:Button id="cancelButton" label="Cancel" styleName="normalButton"
    click="PopUpManager.removePopUp(this)" />
    <mx:Button id="saveButton" label="Save" styleName="normalButton"
    click="parent.saveRecipe()" />
    </mx:HBox>
    </mx:Form>

    But I get an error:
    1061: Call to a possibly undefined method saveRecipe through a reference with
    static type flash.display:DisplayObjectContainer.

    So it's not seeing it. How do I target the parent?


    Handycam Guest

  2. Similar Questions and Discussions

    1. Calling a function on the component's parent.
      How would you go about sending an event in the seeting of a popupWindow? I open a popup window child to parent document. I would like to run an...
    2. How do I call an outer function from a class method function?
      I'm sorry guys but this is a bad day for me. I tried researching this one and was totally stonewalled (see...
    3. #25687 [Ver->Bgs]: "Segmentation fault" - trying to inherit >2 classes and to call parent constr.
      ID: 25687 Updated by: moriyoshi@php.net Reported By: kostyal at realeastnetworks dot com -Status: Verified...
    4. Call parent method indirectly
      -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 To call a method in a class indirectly, you do: $self->$method(@args); To call a specific...
    5. note 25356 deleted from function.get-parent-class by didou
      Note Submitter: apex@prezent.nl ---- Overloading functions <? class basic { function test() { echo "Basic\n"; }
  3. #2

    Default Re: Call a function in Popup's parent??

    Hi Handycam,

    we did it by the following way (may not be the only one)

    Make a custom Dialog AS class with events:
    [Event(name="createDocument", type="MYCreateDocumentEvent")]

    public class MyNewDocumentDialog extends TitleWindow
    {
    ..
    private function dispatchOKEvent():void{
    aEvent = new MYCreateDocumentEvent("createDocument", true);
    dispatchEvent( aEvent );
    }
    }

    Now when you create your PopUpWindow you can add a event listener for the
    event, which is than called.

    AS Code can be like:
    {
    ...
    var pop2:MyNewDocumentDialog= MyNewDocumentDialog(
    PopUpManager.createPopUp(this, MyNewDocumentDialog, true));
    ...
    pop2.addEventListener("createDocument", createDocumentCalled);
    PopUpManager.centerPopUp(pop2);
    }

    private function createDocumentCalled(event:MYCreateDocumentEvent): void{
    // Do something with the event
    }

    Hope it help you.
    If you find another solution I would be glad if you share it ;)

    best regards
    kcell

    kcell Guest

  4. #3

    Default Re: Call a function in Popup's parent??

    Thanks, but I guess I don't know how to create custom events, since your
    example gave me a lot of errors.

    Also, I created the AS file SaveDialogClass.as and an mxml SaveDialog.mxml
    with the type of <custom:SaveDialogClass> but although I was able to pop up the
    window, the mxml layout info was missing (the title window was empty).

    I was also unable to target elements in my window such as the text field
    (sWin.myTextField.text="foo"), Flex could not find the mxml elements. I
    realize I must be doing this wrong, but I am hazy on how to create MXML
    components and AS classes together (I usually just use "straight" mxml
    components).



    Handycam Guest

  5. #4

    Default Re: Call a function in Popup's parent??

    Hi Handycam,

    yes I assumed that, cause the code I posted may show you just the idea and
    also just in actionscript.

    If I find the time tommorow I will try to make a easy example which use mxml.

    best regards,
    kcell

    kcell Guest

  6. #5

    Default Re: Call a function in Popup's parent??

    The part that gets me is
    [Event(name="createDocument", type="MYCreateDocumentEvent")]

    private function dispatchOKEvent():void{
    aEvent = new MYCreateDocumentEvent("createDocument", true);
    dispatchEvent( aEvent );

    I'm trying to do tis all in the mxml document for my dialog. I was using your
    advice and the help files, and came up with

    <mx:Metadata>
    [Event(name="saveRecipe", type="myCustomEvent")]
    </mx:Metadata>

    and then I try this in my script block:
    private function handleSaveClick(aEvent:Event):void {
    aEvent = new myCustomEvent("saveMe", true);
    dispatchEvent(aEvent);
    }

    But I get :
    1180: Call to a possibly undefined method myCustomEvent.

    If I can just grasp this, I think I can do it


    Handycam Guest

  7. #6

    Default Re: Call a function in Popup's parent??

    Ok, I changed it around a bit:

    In the popup window:

    private function handleSaveClick(aEvent:Event):void {
    trace(aEvent.type);
    dispatchEvent(aEvent);
    PopUpManager.removePopUp(this);
    }

    <mx:Button id="saveButton" label="Save" click="handleSaveClick(event)" />

    In the main app:

    [Bindable]
    private var sWin:SaveDialog;

    private function saveDialog():void{
    sWin =
    com.cyor.SaveDialog(PopUpManager.createPopUp(this, com.cyor.SaveDialog,true));
    sWin.fileName = app._stepData0.@title;
    sWin.saveName.setFocus();
    sWin.addEventListener("click", myClickHandler);
    }

    private function myClickHandler(e:Event):void{
    saveRecipe();
    }

    The main function is that "saveRecipe()". This works, but for some reason,
    it's called TWICE. Any ideas?


    Handycam Guest

  8. #7

    Default Re: Call a function in Popup's parent??

    OK, I've got it, if it helps anyone. It's almost what kcell suggested:

    In the popup window component:
    <mx:Metadata>
    [Event(name="foobar", type="flash.events.Event")]
    </mx:Metadata>

    In the script:
    private function handleSaveClick(aEvent:Event):void {
    fileName=saveName.text;
    dispatchEvent(new Event("foobar", true));
    PopUpManager.removePopUp(this);
    }

    Then the button:
    <mx:Button id="saveButton" label="Save" styleName="normalButton"
    click="handleSaveClick(event)" />

    Then in the parent app:

    private var sWin:SaveDialog;

    private function saveDialog():void{
    sWin =
    com.taunton.cyor.SaveDialog(PopUpManager.createPop Up(this,com.taunton.cyor.SaveD
    ialog,true));
    sWin.fileName = app._stepData0.@title;
    sWin.saveName.setFocus();
    sWin.addEventListener("foobar", myClickHandler);
    }

    private function myClickHandler(e:Event):void{
    saveRecipe();
    }

    Handycam Guest

  9. #8

    Default Re: Call a function in Popup's parent??

    Hi Handycam,

    great, you got it, thanks for sharing the code.

    The "custom" event from my "example" was a new as class with extends the event
    class. The reason was that I wanted to send some more infos with the event to
    the parent app.

    best regards,
    kcell



    kcell Guest

  10. #9

    Thumbs up Re: Call a function in Popup's parent??

    I just used this solution and it worked perfectly. Thanks so much for posting!
    Unregistered Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139