2 Replies Latest reply on Feb 23, 2010 10:33 AM by Luis Pedro Ferreira

    Gumbo + DataGroup + AMFPHP

    Luis Pedro Ferreira Level 1

      Hi. I'm trying to detect why i can't populate an ArrayCollection, as data provider of a DataGroup, with data coming from AMFPHP.

       

      All works fine with PHP and on the AMFPHP browser.

      Debugging the Flex application, all the data are received in the result event, but for some reason, i can't populate the ArrayCollection that is going to be the data provider of my DataGroup.

       

      Here's the code:

       

      PHP:
      public function all_colors_enabled(){
            $db=$this->connection();
            $rs=$db->Execute("SELECT * FROM colors WHERE color_status=1 ORDER BY color_code ASC");
            $i=0;
            while (!$rs->EOF){
                 $color_code[$i]['color_id'] = $rs->fields['color_id'];
                 $color_code[$i]['color_code'] = $rs->fields['color_code'];
                 $rs->MoveNext();
                 $i++;
           }
           return $color_code;
      }

      Flex:
      <fx:Script>

           <![DATA[
                import mx.collections.ArrayCollection;
                import mx.rpc.events.ResultEvent;
        

                [Bindable]
                private var categoryArray:ArrayCollection = new ArrayCollection;
        

                private function init():void{
                     ro_categoryService.all_categories_enabled();
                }
        

                private function all_categories_enabled_resultHandler(event:ResultEvent):void{
                     categoryGroup.dataProvider = event.result.category as ArrayCollection;
      (is this necessary?)
                }
           ]]>
      </fx:Script>

      <fx:Declarations>
           <s:RemoteObject id="ro_categoryService" destination="amfphp" source="briconlineServices.categoryServices" showBusyCursor="true">
                <s:method name="all_categories_enabled" result="all_categories_enabled_resultHandler(event)"/>
           </s:RemoteObject>
      </fx:Declarations>

      <s:DataGroup id="categoryGroup" y="150" height="100%" clipAndEnableScrolling="true">
           <s:layout>
                <s:VerticalLayout useVirtualLayout="true" gap="-1"/>
           </s:layout>
           <s:itemRenderer>
                <fx:Component>
                     <s:DataRenderer>
                          <LeftComponent:MenuCategory categoryName="{data.category_name}" categoryColor="{data.category_color_code}"/>
                     </s:DataRenderer>
                </fx:Component>
           </s:itemRenderer>
      </s:DataGroup>

        • 1. Re: Gumbo + DataGroup + AMFPHP
          Luis Pedro Ferreira Level 1

          More information:

           

          If i set the DataGroup data provider like this:

           

          public function all_categories_enabled_resultHandler(e:ResultEvent):void{;
               categoryGroup.dataProvider = e.result;
          }

           

          It returns this error:

          Multiple markers at this line: -dataProvider -1118: Implicit coercion of a value with static type Object to a possibly unrelated type mx.collections:IList.

           

          Probably because e.result is an Array and the DataGrid is expecting an iList as dataprovider, right?

          But how can i fix this??

          • 2. Re: Gumbo + DataGroup + AMFPHP
            Luis Pedro Ferreira Level 1

            SOLUTION:

             

            [Bindable]

            private var categoryArray:ArrayCollection;

             

            public function all_categories_enabled_resultHandler(e:ResultEvent):void{;
                 categoryArray = new ArrayCollection(e.result as Array);
            }

             

            And then set the DataGrou's dataprovider with categoryArray .