[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem assigning data to an itemRenderer component

Posted on 2009-04-24
3
Medium Priority
?
532 Views
Last Modified: 2012-05-06
I actually asked this question before, and I was given the recommendation to look at http://livedocs.adobe.com/flex/3/langref/mx/core/ClassFactory.html. I have a datagrid that has a column defined this way:

<mx:DataGridColumn id="dgc" headerText="Gender" itemRenderer="itemrenderers.ComboBoxRenderer" editable="false"/>

The code of itemrenderers.ComboboxRenderer is simply this:

<?xml version="1.0" encoding="utf-8"?>
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
      dataProvider="{dp}">
      
      <mx:Script>
            <![CDATA[
                  import mx.collections.ArrayCollection;
                  
                  [Bindable]
                  public var dp:ArrayCollection;
            ]]>
      </mx:Script>
      
</mx:ComboBox>

My objective is to pass the following mx:Model to itemrenderers.ComboBoxRenderer to serve as its dataProvider:

<mx:Model id="modelGender">
      <gender>
            <sex index="M" text="Male"/>
            <sex index="F" text="Female"/>
      </gender>
</mx:Model>

Now following the instructions which http://livedocs.adobe.com/flex/3/langref/mx/core/ClassFactory.html leads to, I have a function called setupDataGrid() which is called upon my datagrid's (whose id is "dg1") creationComplete event:

            private function setupDataGrid():void
            {
                  var myComboBoxRenderer:ClassFactory = new ClassFactory(itemrenderers.ComboBoxRenderer);
                  myComboBoxRenderer.properties = { dp: modelGender.sex};
                  dg1.itemRenderer = myComboBoxRenderer;

            }

But when I run it, I get this error:

"TypeError: Error #1034: Type Coercion failed: cannot convert []@158b7d99 to mx.collections.ArrayCollection.
      at mx.core::ClassFactory/newInstance()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\ClassFactory.as:153]
      at mx.controls.dataGridClasses::DataGridColumn/http://www.adobe.com/2006/flex/mx/internal::getMeasuringRenderer()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\dataGridClasses\DataGridColumn.as:1557]
      at mx.controls::DataGrid/commitProperties()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\controls\DataGrid.as:1605]
      at mx.core::UIComponent/validateProperties()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:5807]
      at mx.managers::LayoutManager/validateProperties()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:539]
      at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:689]
      at Function/http://adobe.com/AS3/2006/builtin::apply()
      at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
      at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]"

It is erroring out during the assignment of modelGender.sex (an ArrayCollection object) to the 'dp' property of my itemrenderers.ComboBoxRenderer, and I'm at a loss now. :(

Can anyone see what I'm doing wrong? Thanks.
0
Comment
Question by:elepil
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 24270834
>> It is erroring out during the assignment of modelGender.sex (an ArrayCollection object)
Are you sure that modelGender.sex is an ArrayCollection?

The error says: "... cannot convert []".
Looks like modelGender.sex is more like an Array instead of an ArrayCollection


Could you try changing

        myComboBoxRenderer.properties = { dp: modelGender.sex};

into

        myComboBoxRenderer.properties = { dp: new ArrayCollection(modelGender.sex) };
?
0
 

Author Closing Comment

by:elepil
ID: 31574394
Thank you for responding when nobody did, I really appreciate it. :)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24278122
You're welcome
Thanx 4 axxepting
0

Featured Post

[Video] Oticon Case Study

Open office environments can create the dynamics for innovation, but they also bring some challenges. With over 1,000 employees in an open office, Oticon needed a solution that would preserve the environment while mitigating disruptive background noises.

Watch how they did it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
I came across an unsolved Outlook issue and here is my solution.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question