Question

I'm having difficulty passing json to a datagrid. I get the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@bc292a9 to Array.
    at Function/<anonymous>()[C:\Users\Birger\Dropbox\Rich Media Applications\P006_Project\src\FULLTEST.mxml:10]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.binding::Binding/wrapFunctionCall()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:395]
    at mx.binding::Binding/innerExecute()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:469]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.binding::Binding/wrapFunctionCall()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:395]
    at mx.binding::Binding/execute()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\Binding.as:333]
    at mx.binding::BindingManager$/executeBindings()[E:\dev\4.y\frameworks\projects\framework\src\mx\binding\BindingManager.as:153]
    at FULLTEST/_FULLTEST_ArrayCollection1_i()[C:\Users\Birger\Dropbox\Rich Media Applications\P006_Project\src\FULLTEST.mxml:4]
    at FULLTEST()[C:\Users\Birger\Dropbox\Rich Media Applications\P006_Project\src\FULLTEST.mxml:4]

my code is:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:components="components.*" initialize="getData.send();">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <mx:HTTPService id="getData" url="http://localhost/P006_Project/Query.php" 
                        useProxy="false" method="POST" resultFormat="text" result="getPHPData(event)">  
        </mx:HTTPService>
        <s:ArrayCollection id="acItems" source="{dataArray}" />
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;
            import mx.rpc.events.ResultEvent;

            [Bindable]private var dataArray:ArrayCollection = new ArrayCollection();

            private function initDataGrid():void
            {
                getData.send();
            }

            private function getPHPData(event:ResultEvent):void
            {
                var rawArray:Array;
                var rawData:String = String(event.result);
                rawArray = JSON.parse(rawData) as Array;
                dataArray = new ArrayCollection(rawArray);
            }


        ]]>
    </fx:Script>

    <mx:Accordion id="accItems" creationPolicy="auto">
        <s:NavigatorContent label="Frisdranken">
            <components:FULLTESTCOMP acItems="{acItems}" creationComplete="{initDataGrid()}"/>
        </s:NavigatorContent>
    </mx:Accordion>
</s:Application>

so I'm trying to fill my datagrid with content from my database by converting it into JSON. I'm using a custom component (just an ordinary datagrid in this one).

Was it helpful?

Solution

Here is the problem:

       <s:ArrayCollection id="acItems" source="{dataArray}" />

source needs to be of type "Array" but you're assigning the source to an ArrayCollection object.

You should do:

             <s:ArrayCollection id="acItems" source="{dataArray.source}" />

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top