3 Replies Latest reply on Jun 16, 2009 7:36 AM by lenharts

    Object to ArrayCollection

    lenharts

      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:

       

      [Bindable]

      Private var selectedData:ArrayCollection = new ArrayCollection();

      [Bindable]

      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.