Search code examples
actionscript-3jsondataprovider

Actionscript: unable to assign JSON decoded object as dataProvider


I am trying to use JSON decoded as a dataProvider, but no matter what I try I get errors such as the following:

Error #1034: Type Coercion failed: cannot convert    
mx.collections::ArrayCollection@2a88ae01 to fl.data.DataProvider.

I am only returning a simple JSON object array of 3 elements with 3 properties each.

I am currently doing the following:

  var arr:Array = (JSON.decode(rawData) as Array);

  var dp:ArrayCollection = new ArrayCollection(arr);

  grid.dataProvider = dp;

EDIT - MORE INFO

If I change the last line of the above code to

      grid.dataProvider = new DataProvider(dp);

I get the following error

    TypeError: Error: Type Coercion failed: 
    cannot convert [object Object],[object Object] to Array or DataProvider.

Solution

  • What changing the last line to this?

    grid.dataProvider = new DataProvider(arr);