adobe flex Passing data to and from a pop-up window

adobe flex Passing data to and from a pop-up window

Postby haretu » Thu Apr 07, 2011 10:03 am

Passing data to and from a pop-up window
To make your pop-up window more flexible, you might want to pass data to it or return data from it. To do this, use the following guidelines:

Create a custom component to be your pop-up. In most circumstances, this component is a TitleWindow container.
Declare variables in your pop-up that you will set in the application that creates the pop-up.
Cast the pop-up to be the same type as your custom component.
Pass a reference to that component to the pop-up window, if the pop-up window is to set a value on the application or one of the application's components.
For example, the following application populates a ComboBox in the pop-up window with an Array defined in the main application.

When creating the pop-up, the application casts the pop-up to be of type ArrayEntryForm, which is the name of the custom component that defines the pop-up window. If you do not do this, the application cannot access the properties that you create.

The application passes a reference to the TextInput component in the Application container to the pop-up window so that the pop-up can write its results back to the container. The application also passes the Array of file extensions for the pop-up ComboBox control's data provider, and sets the pop-up window's title. By setting these in the application, you can reuse the pop-up window in other parts of the application without modification, because it does not have to know the name of the component it is writing back to or the data that it is displaying, only that its data is in an Array and it is writing to a TextArea.
Code: Select all
<?xml version="1.0"?>
<!-- containers\layouts\MainArrayEntryForm.mxml -->
<mx:Application xmlns:mx="">

            import mx.managers.PopUpManager;
            import myComponents.ArrayEntryForm;
            public var helpWindow:Object;
            public function displayForm():void {
                /* Array with data for the custom control ComboBox control. */
                var doctypes:Array = ["*.as", "*.mxml", "*.swc"]
                /* Create the pop-up and cast the
                   return value of the createPopUp()
                   method to the ArrayEntryForm custom component. */
                var pop1:ArrayEntryForm = ArrayEntryForm(
                    PopUpManager.createPopUp(this, ArrayEntryForm, true));
                /* Set TitleWindow properties. */
                pop1.title="Select File Type";
                /* Set properties of the ArrayEntryForm custom component. */
                pop1.targetComponent = ti1;
                pop1.myArray = doctypes;

    <mx:TextInput id="ti1" text=""/>
    <mx:Button id="b1" label="Select File Type" click="displayForm();"/>
Posts: 132
Joined: Sat Jan 08, 2011 9:56 pm

Return to Adobe FLEX Flash

Who is online

Users browsing this forum: No registered users and 1 guest