7 Replies Latest reply on Dec 18, 2010 6:18 AM by saisri2k2

    TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array

    Whitetimer Level 1

      Hi All

       

      I am trying to code a shop front and i keep getting this error message

       

      TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array.
      

       

      This is the code i have

       

      <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
          <fx:Declarations>
              <fx:Model id="shopDataModel" source="../../Data/XML/shopdata.xml"/>
              <s:ArrayCollection id="shopDataArray" source="{shopDataModel.shopitem}"/>
          </fx:Declarations>
      
          <!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      
          <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      
          <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      
          <fx:Script>
              <![CDATA[
              // import statements ----------------------------------------
      
              import VO.ShopItem;
      
              import mx.collections.ArrayCollection;
      
              import flash.net.URLLoader;
              import flash.net.URLRequest;
      
              import mx.collections.ArrayCollection;
              import mx.managers.CursorManager;
      
              // constant declarations ------------------------------------
      
              // variable declarations ------------------------------------
              [Bindable]
              public var shopItems:ShopItem = new ShopItem();
      
              // getter/setters -------------------------------------------
      
              // helper methods -------------------------------------------
      
              // event handlers -------------------------------------------
      
              protected function loadShopData():void {
                  for (var i:int = 0; i < shopDataArray.length; i++)
                  {
                      var shopItemObj:Object = shopDataArray.getItemAt(i);
                      var shopItemVO:ShopItem = new ShopItem();
                      shopItemVO.category = shopItemObj.category;
                      shopItemVO.id = int(shopItemObj.id);
                      shopItemVO.name = shopItemObj.name;
                      shopItemVO.information = shopItemObj.information;
                      shopItemVO.image = shopItemObj.image;
                      shopItemVO.price = Number(shopItemObj.price);
                      shopDataArray.setItemAt(shopItemVO, i);
                  }
              }
      

       

       

      Any suggestions please ?

       

      many Thanks

        • 1. Re: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array
          Flex harUI Adobe Employee

          Could be the array of one issue.  Search past thread on ArrayUtil and on my

          blog

          --

          Alex Harui

          Flex SDK Team

          Adobe System, Inc.

          http://blogs.adobe.com/aharui

          • 2. Re: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array
            Whitetimer Level 1

            Thanks for the reply, but still having problems sorting this error out ......

            • 3. Re: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array
              saisri2k2 Level 4

                <s:ArrayCollection id="shopDataArray" source="{shopDataModel.shopitem}"/>

              in the above line confirm that the shopDataModel.shopitem is not an arrayCollection, looks like shopitem is an simpleobject

              • 4. Re: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array
                Whitetimer Level 1

                It should have been an ArrayList and now it works.  But now i am having trouble passing the data to a custom dataGrid Component ...

                 

                <?xml version="1.0"?>
                <s:Group
                        xmlns:fx="http://ns.adobe.com/mxml/2009"
                        xmlns:s="library://ns.adobe.com/flex/spark"
                        xmlns:mx="library://ns.adobe.com/flex/mx"
                        xmlns:comp='ShoppingCart.Components.*'
                        width="900" height="100%">
                
                    <!-- Properties of the parent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <s:layout>
                        <s:HorizontalLayout />
                    </s:layout>
                    <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <fx:Declarations>
                        <fx:Model id="shopDataModel" source="../Data/XML/shopdata.xml" />
                        <s:ArrayList id="shopDataArray" source="{shopDataModel.shopitem}" />
                    </fx:Declarations>
                
                    <!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <fx:Script>
                        <![CDATA[
                
                
                
                        // import statements ----------------------------------------
                        import ShoppingCart.VO.ShopItemVO;
                
                        // variable declarations ------------------------------------
                        [Bindable]
                        public var shopItems:ShopItemVO = new ShopItemVO();
                        // getter/setters -------------------------------------------
                
                        // helper methods -------------------------------------------
                
                        // event handlers -------------------------------------------
                        protected function loadShopData():void
                        {
                            for (var i:int = 0; i < shopDataArray.length; i++)
                            {
                                var shopItemObj:Object = shopDataArray.getItemAt(i);
                                var shopItemVO:ShopItemVO = new ShopItemVO();
                                shopItemVO.id = int(shopItemObj.id);
                                shopItemVO.name = shopItemObj.name;
                                shopItemVO.description = shopItemObj.description;
                                shopItemVO.image = shopItemObj.image;
                                shopItemVO.price = Number(shopItemObj.price);
                                shopDataArray.setItemAt(shopItemVO, i);
                            }
                        }
                
                
                
                        ]]>
                    </fx:Script>
                
                    <!-- States ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <s:states>
                        <s:State id="shopGridView" name="shopGridView" />
                        <s:State id="shopTileView" name="shopTileView" />
                    </s:states>
                
                    <!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <comp:CompShopDataGrid id="compShopDataGrid" excludeFrom="shopTileView" dataProvider="{shopDataArray}" />
                    <comp:CompShopTileList id="compShopTileList" excludeFrom="shopGridView"/>
                
                    <comp:CompShoppingCart id="compShoppingCart" />
                

                 

                And my Custom DataGrid looks like this

                 

                <?xml version="1.0"?>
                <mx:DataGrid
                        xmlns:fx="http://ns.adobe.com/mxml/2009"
                        xmlns:s="library://ns.adobe.com/flex/spark"
                        xmlns:mx="library://ns.adobe.com/flex/mx"
                        width="100%">
                
                    <!-- Properties of the parent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <fx:Declarations>
                        <!-- Place non-visual elements (e.g., services, value objects) here -->
                    </fx:Declarations>
                
                    <!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <fx:Script>
                        <![CDATA[
                
                
                        // import statements ----------------------------------------
                
                        // variable declarations ------------------------------------
                
                        // getter/setters -------------------------------------------
                
                        // helper methods -------------------------------------------
                
                        // event handlers -------------------------------------------
                
                        ]]>
                    </fx:Script>
                
                    <!-- States ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                
                    <!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                    <mx:columns>
                        <mx:DataGridColumn width="100" headerText="Item ID #" dataField="{data.id}" />
                        <mx:DataGridColumn headerText="Item Name" dataField="{data.name}" />
                        <mx:DataGridColumn width="100" headerText="Item Price £" dataField="{data.price}" />
                    </mx:columns>
                
                </mx:DataGrid>
                

                 

                Many Thanks

                • 6. Re: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array
                  Whitetimer Level 1

                  No i dont get an error now.  But the data is not appearing in the Custom DataGrid.

                  • 7. Re: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@ad73f7c1 to Array
                    saisri2k2 Level 4

                    looks like your arraylist is not bindable,

                     

                    or t the end of the for loop, do

                     

                    dataGrid.dataprovider = arrayListId;

                    datagrid.invalidateList();

                     

                     

                    If this answer helped you, Please mark it as such.