Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
Handycam #1
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
-
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... -
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... -
#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... -
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... -
note 25356 deleted from function.get-parent-class by didou
Note Submitter: apex@prezent.nl ---- Overloading functions <? class basic { function test() { echo "Basic\n"; } -
kcell #2
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
-
Handycam #3
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
-
kcell #4
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
-
Handycam #5
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
-
Handycam #6
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
-
Handycam #7
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
-
kcell #8
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
-
Unregistered #9
Re: Call a function in Popup's parent??
I just used this solution and it worked perfectly. Thanks so much for posting!
Unregistered Guest



Reply With Quote

