1 Reply Latest reply on Jun 28, 2008 10:40 PM by Gregory Lafrance

    Problem to pass dataProvider to a separate component

    cyber fyb
      Previously, I declared a form dynamically based on the row clicked from a datagrid. Since I have many form to take care from the same application, I started to use component to facilitate and minizing code source from the main page. This is something very well demonstrate from Adobe and I think it is also consider as a best practice.

      Everything works good except for one thing. I have a ComboBox on the form from the separate component and I need to populate it from the main page (let say the main page is called main.mxml and the component's page is called myForm.mxml). I successfully populate each fields of the form by using this method:

      var _myForm:myForm = new myForm();
      _myForm.fCatTitle.text = vCategories.getItemAt(event.rowIndex).catTitle;

      Well, we are inside a function where I used the event from a click on a datagrid so this is why I used event.rowIndex. Also, fCatTitle is defined as a TextInput inside the myForm component.

      Now, when I arrive to the ComboBox, I get an error:

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at admin/clickDataGridCategory()[C:\Documents and Settings\DJ FYB\My Documents\CharlesValcourt\includes\charlesvalcourtADMIN_logique.as:371]
      at admin/__dgCategories_itemClick()[C:\Documents and Settings\DJ FYB\My Documents\CharlesValcourt\src\admin.mxml:168]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\co re\UIComponent.as:9051]
      at mx.controls.listClasses::ListBase/mouseClickHandler()[E:\dev\3.0.x\frameworks\projects\fr amework\src\mx\controls\listClasses\ListBase.as:9027]

      This is based on the following code:

      _catFormEdit.fCatEditShowOrder.dataProvider = vCategories;
      _catFormEdit.fCatEditShowOrder.labelField = "catShowOrder";
      _catFormEdit.fCatEditShowOrder.selectedIndex = vCategories.getItemAt(event.rowIndex).catShowOrder;

      The system do not accept the first line concerning the dataProvider. vCategories is a ArrayCollection where I have all my data concerning "categories". Previously, this similar method was working when I used to build the form dynamically (var myComboBox:ComboBox = new ComboBox(); myComboBox.dataProvider = vCategories; and so on to populate the myComboBox) but I was on the main.mxml. Now that I want to pass it to the myForm.mxml, it does not working. But it is the same method so I must missing a specific knowledge concerning "passing dataProvider to another component". I started to search on Internet but I guess Flex community is not enought large yet to get into this specific issue. But I will continue my research. In the meantime, if anybody here have an idea about it, please let me know.