Question

I am not sure what I am doing wrong so maybe someone can explain it to me.

I have an array of object that amfphp is sending back and it looks like this:

(Object)#0
   content = (Array)#1
     [0] (Object)#2
       config = "1"
       id = "3"
       param = "3"
       title = "categorypreview"
     [1] (Object)#3
       config = "0"
       id = "1"
       param = "-1"
       title = "highestdisplay"
     [2] (Object)#4
       config = "0"
       id = "8"
       param = "-1"
       title = "featured"
   header = (Array)#9
     [0] (Object)#10
       config = "1"
       id = "9"
       param = "5"
       title = "categorymenu"
     [1] (Object)#11
       config = "1"
       id = "6"
       param = "1"
       title = "adzones"

The mxml that I am using is:

<s:List id="headerList" y="52" left="10" width="200" height="150">
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>
</s:List>
<mx:DataGrid id="mydatagrid" x="10" y="214">
    <mx:columns>
        <mx:DataGridColumn headerText="Column 1" dataField="title"/>
        <mx:DataGridColumn headerText="Column 2" dataField="param"/>
    </mx:columns>
</mx:DataGrid>

The actionscript is:

protected function getLayoutResultHandler(event:ResultEvent):void
        {
            mydatagrid.dataProvider = event.result.header;
            headerList.dataProvider = event.result.header;
        }

The datagrid is just there for a test. The problem that I am having is the datagrid populates with the values of the header array but the list gives me an error of:

Type Coercion failed: cannot convert []@dcc5629 to mx.collections.IList

What am I doing wrong?

Was it helpful?

Solution

I figured it out!!

Here is what I had to do, in the actionscript I modified my function to be this:

protected function getLayoutResultHandler(event:ResultEvent):void
{
     var header:ArrayCollection = new ArrayCollection(event.result.header);
     headerList.dataProvider = header;
     mydatagrid.dataProvider = header;
}

Now everything works.

OTHER TIPS

Try casting event.result.header as a collection of some kind. My best guess is that the data returned from your amfphp call isn't being cast as a data type and your List doesn't know how to handle it.

protected function getLayoutResultHandler(event:ResultEvent):void
{
  mydatagrid.dataProvider = event.result.header as ArrayCollection;
  headerList.dataProvider = event.result.header as ArrayCollection;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top