views:

362

answers:

1

I had to reformat my question because I realized I was using incorrect flex method. But still a similar issue occurs:

        private function passForm():void {


            PopUpManager.addPopUp(passTitleWindow, this, true);
            PopUpManager.centerPopUp(passTitleWindow);


        } 

                            <s:Button includeIn="Detail" x="10" y="329" 
                                  id= "btn1"
                                  label="Pass"
                                  click="passForm()" 
                                  visible="{hasScreen}" />

I click and popup does not display.

+1  A: 

You can't instantiate an item based on it's id. Make your TitleWindow into another class and instantiate that.

PassTitleWindow.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    title="Pass"
    layout="vertical"
    width="480"
    height="240"
    titleStyleName="titleText"
    backgroundColor="white"
    backgroundAlpha="1.0"
    borderColor="white"
    borderAlpha="1.0"
    cornerRadius="0"
    showCloseButton="true"
    implements="mx.core.IDataRenderer">

    <fx:Script>
        <![CDATA[

            private var _data:Object;
            [Bindable(event="dataChange")]
            /**
             *  implementing mx.core.IDataRenderer.
             *  Set this value from outside
             */
            public function get data():Object
            {
                return _data;
            }

            /**
             *  @private
             */
            public function set data(value:Object):void
            {
                if (_data == value) 
                    return;
                _data = value;
                dispatchEvent(new Event("dataChange"));
            }
        ]]>
    </fx:Script>

    <mx:Text text="Please fill out the following criteria and then click continue."
        width="100%"
        styleName="headingText"/>

    <mx:Form x="-12" y="150" id="passView">

        <mx:FormItem label="Age" >
            <s:TextInput id="ageTextInput" "@{data.age}"/>
        </mx:FormItem>
        <mx:FormItem label="Grade" >
            <s:TextInput id="gradeTextInput"/>
        </mx:FormItem>

    </mx:Form>

</mx:TitleWindow>

SampleApp.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    creationComplete="creationCompleteHandler()">

    <fx:Script>
        <![CDATA[

            import mx.managers.PopUpManager;

            protected var passWindow:PassTitleWindow = new PassTitleWindow;

            protected function creationCompleteHandler():void
            {
                createForm();
            }

            protected function createForm():void
            {
                passWindow = PopUpManager.createPopUp(this, PassTitleWindow, true) as PassTitleWindow;
                passWindow.data = studentGrid.selectedItem;
                PopUpManager.centerPopUp(passWindow);
            }
        ]]>
    </fx:Script>

</s:Application>

Hope that helps, Lance

viatropos
Thanks for response. Problem I was having with that approach was that in another component, I was getting studentsGrid is undefined method:<s:TextInput id="ageTextInput" text="@{studentsGrid.selectedItem.age}"/>The reason why is studentsgrid is defined in application and not component and I guess the component can't communicate with the datagrid in application.
JohnMerlino
I see. Its best practice to separate your data so the item renderers don't have to reference their parent. You can do that by implementing IDataRenderer (one get/set method for "data"), and setting the data to the selected item. I've updated the code to show that. Let me know if that helps.
viatropos
Finally got it to update the correct item, courtesy of your advice and this link: http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_7.html. I don't think I fully comprehend this line: dispatchEvent(new Event("dataChange")). But I will read the article again and see if it offers any insights. Thanks for leading me to the right path.
JohnMerlino
glad it worked out. that dispatchEvent line makes binding work. the whole get/set block is what [Bindable] public var data:Object is converted to! Really cool stuff. If you wanna get ahead of the game, study this super advanced data binding video. http://tv.adobe.com/watch/360flex-conference/diving-in-the-data-binding-waters-by-michael-labriola. It's more about hardcore flex things you can't find anywhere, than just data binding. best.
viatropos