Passing data from popup to popup in Flex
I have a web application which contains a data grid. Double clicking on any row of that grid will open a popup (lets call it popup1). Now this popup1 again opens a new popup(lets call it popup2).
When I close the popup2, I need pass an Object to popup1. Which is the easiest way to do that?
Thanks in Advance
(PS: While opening popup2 from popup1, I am adding an开发者_如何学Go event listener on Close event of popup2)
I would create a custom event you would fire off when popup2 is closed. Just before you close popup2 add your data to the event and fire it off. Popup1 would have an event listener for MyCustomEvent and could access the myDataToPass property. Something like:
MyCustomEvent:
package
{
import flash.events.Event;
import mx.collections.ArrayCollection;
public class MyCustomEvent extends Event
{
public var myDataToPass:ArrayCollection;
public function MyCustomEvent (type:String, bubbles:Boolean=true, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
}
}
Passing the data:
var newEvent:MyCustomEvent = new MyCustomEvent();
newEvent.myDataToPass = <your data here>;
dispatchEvent(newEvent);
IMHO the solution suggested bu @ajay87 is wrong.
popup1 should not "know" popup2, they should be decoupled, views should not call function in other views.
this sort of behavior should be implemented using events, you should open up popup2 then dispatch and event (listen to it in popup 2).
the other way around is the same, you should get the data using an event dispatched from the popup 2, not activate a function or anything else like that.
this way, your views are decoupled and will not break of you change the implementation, also, you will be able to show popup 2 without this function and vice versa.
I would just make and call a new function which will make the popup2 window (via PopUpManager) and pass the object to this function. The child of popup2 (presumably a custom component of a titlewindow or panel) can then be populated from the object, or you can pass the object to it.
private function displayPopUp2(object:Object):void
{
//create an instance of your window
var popup2:CustomComponentPopUp2 = new CustomComponentPopUp2();
//pass the object data to a function within side this to populate fields, or this could be done through constructor.
popup2.populateData(object);
//then use popup manager to display popup... passing the popup2 as it's child.
PopUpManager.addPopUp(popup2);
}
This is one way of doing so.
精彩评论