2 Replies Latest reply on Mar 11, 2010 1:24 PM by JohnMerlino

    "access of undefined property studentsGrid" in flex component

    JohnMerlino Level 1

      Hey all,

       

      I'm using flash builder and I moved a form from the application to a TitleWindow component called passTitleWindow. The reason is all the tutorials I found on how to create popup forms in flex all used components to create the form. So I moved this code to a component:

       

          <mx:Form includeIn="Detail" x="-12" y="150" id="passView">
             
              <mx:FormItem label="Age" >
                  <s:TextInput id="ageTextInput" text="@{studentsGrid.selectedItem.age}"/>
              </mx:FormItem>
              <mx:FormItem label="Grade">
                  <s:TextInput id="gradeTextInput" text="@{studentsGrid.selectedItem.grade}"/>
              </mx:FormItem>
          </mx:Form>

       

      I get an access of undefined property studentsGrid error and "State Detail was referenced without being declared" error. Any suggestions on how to resolve this? Thanks.

        • 1. Re: "access of undefined property studentsGrid" in flex component
          JohanVelthuis

          Hello John,

           

          I assume you're code was working, while the form was in the application together with your datagrid.

           

          The problem is that the titlewindow component you created doesn't know the studentsgrid because it's not part of the titlewindow component.

          You could argue if this is the best way to go, it's probably easier to use a dataservice as dataprovider for your students grid and then use that also for your popup.

           

          to show the popup you'll probably do something like

           

          var popupClass:Class = yourTitleWinComponentWithTheForm as Class;

          var titleWin:* = PopUpManager.createPopUp(DisplayObject(Application.application.parentDocument), popupClass, true) as popupClass;
          PopUpManager.centerPopUp(titleWin);

           

           

          What you can try is add this to your titlewindow script tag (or create one)

          [Bindable]

          public var studentsGrid:DataGrid;

           

          In your application where you call the popup you add the last line in the next block:

           

          var popupClass:Class = yourTitleWinComponentWithTheForm as Class;

          var titleWin:* = PopUpManager.createPopUp(DisplayObject(Application.application.parentDocument), popupClass, true) as popupClass;
          PopUpManager.centerPopUp(titleWin);

          titleWin.studentsGrid = studentsGrid;

           

          where the first 'studentsGrid' represents the public var you've created in your component and the second studentGrid refers to the studentsGrid in you're main application

          If this still doesn't work, the problem is the order which things happen, the public var studentsGrid in you're component should be set before the form in the component initializes.

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

           

          the includeIn part can be removed since the form is no longer part of a state of the application, but as a popup.

           

          Hope this helps

           

          Johan Velthuis

          • 2. Re: "access of undefined property studentsGrid" in flex component
            JohnMerlino Level 1

            Thanks for the response. Making those changes left  an error message:

             

            "Access of possibly undefined property application through a reference with static type Class"

             

            for the line below in the main application:

             

            var titleWin:* = PopUpManager.createPopUp(DisplayObject(Application.application.parentDocument), popupClass, true) as popupClass;