Question

I have an array that i am using to store a collection of objects. My application allows the user to add new objects to the array and edit the content of the objects. all the objects in the array are of the same type and the problem i am having is that if i add a new object or edit an existing object then all the objects contained in the array become exact copies of the newly added object. Is there any way to stop this?

In my Application i have an object that stores an ArrayCollection:

public class MyArray
{
    public var array:ArrayCollection = new ArrayCollection;
}

i have an object that i wish to store instances of in this array:

public class MyObject
{
    public var things:String;
}

My Main mxml file displays all the items in MyArray in a datagrid which is held in an actionscript file:

<App xmlns:par="http://spicefactory.org/parsley">
    <fx:Declarations>
        <par:ContextBuilder config="MainContext"/>
        <par:Configure/>
        <par:FastInject property="mainpm" type="{MainPM}"/>
    </fx:Declarations>
    <fx:Script>
         [Inject][Bindable]
         public var mainpm:MainPM;
    <fx:Script>

and then the actionscript file:

public class MainPM
{
    [inject][Bindable]
    public var thearray:MyArray;

    public function addNew(thingtoadd:MyObject):void
    {
        thearray.addItem(thingtoadd);
    }
}

I have tried to include the relevant code as the application is quite large but if more information is needed i can provide it.

Was it helpful?

Solution

Ok so the way to sole this was to create a new instance of MyObject and add that to MyArray instead.

public function addNew(thingtoadd:MyObject):void
{
    var addobj:MyObject = new MyObject;
    addobj.things = thingtoadd.tings;
    thearray.addItem(addobj);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top