Error: Implicit coercion of a value with static type Object to a possibly unrelated type mx.collections:ArrayCollection.
I've defined several variables as ArrayCollections like this:
Private var selectedData:ArrayCollection = new ArrayCollection();
Private var Fruits:ArrayCollection = new ArrayCollection();
From an external XML file, I've populated the variable "Fruits" as an ArrayCollection like this:
Fruits=event.result.<>.<>; where <> is taken from the XML file structure.
I've verified that Fruits is populated correctly at "creationComplete" using the HTTPService.
From a list called listData, the user selects an item and I capture the index of this item:
var listChoiceIndex:int = listData.getItemIndex(event.currentTarget.selectedItem);
One of the items in the list is "Fruits", and let's assume that the user picks Fruits from the list.
From this user selection, I want to populate my ArrayCollection variable "selectedData" like this:
selectedData = listData.getItemAt(listChoiceIndex);
If the expression "getItemAt(listChoiceIndex)" is "Fruits", then I want selectedData = Fruits, but with this construction, I get an error:
"Implicit coercion of a value with static type Object to a possibly unrelated type mx.collections.ArrayCollection"
How can I populate an array collection from an Object name or even a string name that represents another arraycollection variable name?
Thanks and this is driving me mad. I'm a newbie.
selectedData = new ArrayCollection([listData.getItemAt(listChoiceIndex)]);
Great - that helped. The error has disappeared, but the selectedData ArrayCollection didn't fully populate. The repeating elements of the XML contents are not there, but the category elements of the XML contents are populated. I'll keep playing with it now that the error has disappeared. Thanks!
I get it now. Your suggested statement created a new ArrayCollection called selectedData and entered the string "Fruits" as the first element. So it did not populate the ArrayCollection selectedData with the contents of the ArrayCollection Fruits. Good try and I thought you nailed it for a while there.