2 Replies Latest reply on May 9, 2009 6:19 AM by Gregory Lafrance

    Access the custom component property in Main Application

    hclselvs Level 1

      Hi,

       

      I would like to know, how to access the custrom component's property in Main application. For example, I have a Datagrid in my custom component and it's ID is 'DG1' and I need to access this 'DG1' in my Main application. Can you please guide me how do I achieve this?

       

      Thanks in Advance,

      Srinivasan S

        • 1. Re: Access the custom component property in Main Application
          thedex1 Level 1

          Here is the rough sketch:

           

          Custom_Component:

           

          Property_1

          Property_2

           

           

          Main Application:

          public var CC1:Custom_Compnent = new CustomCompnent();

          CC1.Property_1 = value;

          CC1.Property_2 = somevalue;

           

          Let me know if this helped.

           

          ...

          .:. WAHAB

          • 2. Re: Access the custom component property in Main Application
            Gregory Lafrance Level 6

            Here is an example of accessing the custom component from MXML and from ActionScript.

             

            Bear in mind that if the root of your custom component in this case where VBox instead of DataGrid, you would need to give the DataGrid an ID and access that in ActionScript in the main app like  myVB.myDG.dataProvider.

             

            ------------- components/MyDataGrid.mxml --------------------

            <?xml version="1.0" encoding="utf-8"?>
            <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml">
              <mx:columns>
                <mx:DataGridColumn headerText="ID" dataField="id"/>
                <mx:DataGridColumn headerText="Food" dataField="food"/>
                <mx:DataGridColumn headerText="Category" dataField="category"/>
              </mx:columns>
            </mx:DataGrid>

             

            ---------------- MainApp.mxml ------------------------

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              xmlns:comp="components.*" creationComplete="init();">
              <mx:Script>
                <![CDATA[
                  import mx.collections.ArrayCollection;
                 
                  private function init():void{
                    dg2.dataProvider = myAC;
                  }
                 
                  [Bindable] private var myAC:ArrayCollection = new ArrayCollection([
                    {id: 1, food: "carrots", category: "vegetables"},
                    {id: 2, food: "beans", category: "vegetables"}
                  ]);
                ]]>
              </mx:Script>
              <comp:MyDataGrid dataProvider="{myAC}"/>
              <comp:MyDataGrid id="dg2"/>
            </mx:Application>