You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by bilbosax <wa...@comcast.net> on 2016/09/28 23:54:15 UTC

Rookie ArrayCollection Question

So I have a 2D ArrayCollection that has about 40k records in it with about 40
elements in each record.  I need to add an element or property to the end of
each record so that each record now contains 41 elements, but have no idea
how to do this.  Any suggestions?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Rookie ArrayCollection Question

Posted by Kyle McKnight <ka...@gmail.com>.
Are you meaning you have an array of arrays? As far as I know you'd just
create a loop to go through them and add it.

Because of the number of items in the array and the size of the data you're
working with you might have to do it in chunks.

Pass a start and end index into a function to run though the elements at
those positions and then dispatch an event to move on to the next chunk
when the previous chunk is finished.

Or am I misunderstanding what you mean?

On Sep 28, 2016 7:59 PM, "bilbosax" <wa...@comcast.net> wrote:

> So I have a 2D ArrayCollection that has about 40k records in it with about
> 40
> elements in each record.  I need to add an element or property to the end
> of
> each record so that each record now contains 41 elements, but have no idea
> how to do this.  Any suggestions?
>
>
>
> --
> View this message in context: http://apache-flex-users.
> 2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Rookie ArrayCollection Question

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> var origArray:Array = new Array();
> var newArray:Array = new Array();
> 
> origArray = compArrayCollection.source;
> for each(var o:Object in origArray) {
> 	o.newProperty = true;
> 	newArray.push(o);
> }

No need for the push. All that does is duplicate the original object at the end of the array. All of the the objects in the array will have the new property without the push.

A for each is likely to be slower that traditional for i =0; i <length; i++ etc etc style loop for a large number of items, but try it in the profiler to see.

Thanks,
Justin

Re: Rookie ArrayCollection Question

Posted by Kyle McKnight <ka...@gmail.com>.
You can only add new properties to a class if it is declared as dynamic.
You can also add new properties to generic Objects. You might have to give
more info as to what "CustomDatatype" is and how it's created.


Kyle McKnight
Senior UI Engineer - Accesso
602.515.1444 (M)

On Wed, Sep 28, 2016 at 9:16 PM, bilbosax <wa...@comcast.net> wrote:

> If I understand correctly, your "addItem" method will only add a record to
> the bottom of the arrayCollection, I don't believe that it will add a
> property to the end of each record.  I am looking for something like this I
> think, where compsArrayCollection is my original dataset:
>
> var origArray:Array = new Array();
> var newArray:Array = new Array();
>
> origArray = compArrayCollection.source;
> for each(var o:Object in origArray) {
>         o.newProperty = true;
>         newArray.push(o);
> }
>
> compArrayCollection.source = newArray;
>
> My compArrayCollection is populated by a PHP service and I think that is
> why
> I am having trouble with this.  I get the error:
>
> Error #1056: Cannot create property newProperty on
> valueObjects.CustomDatatype6
>
> CustomDatatype6 was created during the service formation, and does not seem
> to like me trying to add to any of its properties.
>
>
>
> --
> View this message in context: http://apache-flex-users.
> 2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13651.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Rookie ArrayCollection Question

Posted by Kyle McKnight <ka...@gmail.com>.
Actually you would need to do new
ArrayCollection(compArrayCollection.source.concat());

Also, this won't work if the elements of compArrayCollection are also
complex such as other ArrayCollections. You'd have to do a deep copy.

Here is a stackoverflow that goes over it.

http://stackoverflow.com/questions/7918194/how-can-i-copy-an-arraycollection-of-transfer-objects-in-actionscript


Kyle McKnight
Senior UI Engineer - Accesso
602.515.1444 (M)

On Thu, Sep 29, 2016 at 6:19 AM, Kyle McKnight <ka...@gmail.com> wrote:

> ArrayCollections are a complex data type  meaning they are passed around
> by reference. You are actually passing a pointer to the array. The pointer
> points to the memory location. You'll have to make a copy of the array.
>
> Try
>
> Comps.dataProvider = compArrayCollection.source.concat();
>
> Google passing by value and passing by reference to learn the difference
> between how simple and complex data types are handled
>
> On Sep 29, 2016 2:17 AM, "bilbosax" <wa...@comcast.net> wrote:
>
>> Thanks again for the help Justin.  Have another question for you regarding
>> ArrayCollections.  My main app loads an ArrayCollection from a service.  I
>> then pass it to an ArrayCollection in a component by a simple assignment:
>>
>> Comps.dataArrayCollection = compArrayCollection;
>>
>> So I am setting the dataArrayCollection in my Comps component to the
>> values
>> in my compArrayCollection in the main app.  What is weird though is that
>> whenever I change any values in the dataArrayCollection, they are also
>> changing back in my compArrayCollection back in the main app.  I don't
>> want
>> this to happen, I want their values to be independent of one another once
>> the values are passed.  Is there any way to make this not happen?
>>
>> Thanks,
>> Bill
>>
>>
>>
>> --
>> View this message in context: http://apache-flex-users.23333
>> 46.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13662.html
>> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>>
>

Re: Rookie ArrayCollection Question

Posted by bilbosax <wa...@comcast.net>.
Thanks for the heads up kamcknig.  I will read up!



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13679.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Rookie ArrayCollection Question

Posted by Kyle McKnight <ka...@gmail.com>.
ArrayCollections are a complex data type  meaning they are passed around by
reference. You are actually passing a pointer to the array. The pointer
points to the memory location. You'll have to make a copy of the array.

Try

Comps.dataProvider = compArrayCollection.source.concat();

Google passing by value and passing by reference to learn the difference
between how simple and complex data types are handled

On Sep 29, 2016 2:17 AM, "bilbosax" <wa...@comcast.net> wrote:

> Thanks again for the help Justin.  Have another question for you regarding
> ArrayCollections.  My main app loads an ArrayCollection from a service.  I
> then pass it to an ArrayCollection in a component by a simple assignment:
>
> Comps.dataArrayCollection = compArrayCollection;
>
> So I am setting the dataArrayCollection in my Comps component to the values
> in my compArrayCollection in the main app.  What is weird though is that
> whenever I change any values in the dataArrayCollection, they are also
> changing back in my compArrayCollection back in the main app.  I don't want
> this to happen, I want their values to be independent of one another once
> the values are passed.  Is there any way to make this not happen?
>
> Thanks,
> Bill
>
>
>
> --
> View this message in context: http://apache-flex-users.
> 2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13662.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Rookie ArrayCollection Question

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> So I am setting the dataArrayCollection in my Comps component to the values
> in my compArrayCollection in the main app.  What is weird though is that
> whenever I change any values in the dataArrayCollection, they are also
> changing back in my compArrayCollection back in the main app.

Not weird at all what you have is two array collections that contains references to the same objects, if you change one then other one will also changes.

Code like this:
var ac:ArrayCollection = new ArrayCollection(someArray);

or this:

var ac:ArrayCollection = new ArrayCollection(otherAC.source);

Will make a shallow copies like this.

>  I don't want this to happen, I want their values to be independent of one another once
> the values are passed.  Is there any way to make this not happen?

In that case you need to duplicate or deep copy the objects one way to do this is this:

var ac:ArrayCollection = new ArrayCollection(ObjectUtils.copy(otherAC.source) as Array);

But realise you now have doubled the memory needed to store everything.

Thanks,
Justin

Re: Rookie ArrayCollection Question

Posted by Deepak MS <me...@gmail.com>.
var arr:Array = ObjectUtil.copy(compArrayCollection.toArray()) as Array;
Comps.dataArrayCollection = new ArrayCollection(arr);

On Thu, Sep 29, 2016 at 12:01 PM, Deepak MS <me...@gmail.com>
wrote:

> try this:
>
> Comps.dataArrayCollection = (ObjectUtil.copy(compArrayCollection.toArray())
> as Array);
>
> On Thu, Sep 29, 2016 at 11:41 AM, bilbosax <wa...@comcast.net> wrote:
>
>> Thanks again for the help Justin.  Have another question for you regarding
>> ArrayCollections.  My main app loads an ArrayCollection from a service.  I
>> then pass it to an ArrayCollection in a component by a simple assignment:
>>
>> Comps.dataArrayCollection = compArrayCollection;
>>
>> So I am setting the dataArrayCollection in my Comps component to the
>> values
>> in my compArrayCollection in the main app.  What is weird though is that
>> whenever I change any values in the dataArrayCollection, they are also
>> changing back in my compArrayCollection back in the main app.  I don't
>> want
>> this to happen, I want their values to be independent of one another once
>> the values are passed.  Is there any way to make this not happen?
>>
>> Thanks,
>> Bill
>>
>>
>>
>> --
>> View this message in context: http://apache-flex-users.23333
>> 46.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13662.html
>> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>>
>
>

Re: Rookie ArrayCollection Question

Posted by Deepak MS <me...@gmail.com>.
try this:

Comps.dataArrayCollection = (ObjectUtil.copy(compArrayCollection.toArray())
as Array);

On Thu, Sep 29, 2016 at 11:41 AM, bilbosax <wa...@comcast.net> wrote:

> Thanks again for the help Justin.  Have another question for you regarding
> ArrayCollections.  My main app loads an ArrayCollection from a service.  I
> then pass it to an ArrayCollection in a component by a simple assignment:
>
> Comps.dataArrayCollection = compArrayCollection;
>
> So I am setting the dataArrayCollection in my Comps component to the values
> in my compArrayCollection in the main app.  What is weird though is that
> whenever I change any values in the dataArrayCollection, they are also
> changing back in my compArrayCollection back in the main app.  I don't want
> this to happen, I want their values to be independent of one another once
> the values are passed.  Is there any way to make this not happen?
>
> Thanks,
> Bill
>
>
>
> --
> View this message in context: http://apache-flex-users.
> 2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13662.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Rookie ArrayCollection Question

Posted by bilbosax <wa...@comcast.net>.
Thanks again for the help Justin.  Have another question for you regarding
ArrayCollections.  My main app loads an ArrayCollection from a service.  I
then pass it to an ArrayCollection in a component by a simple assignment:

Comps.dataArrayCollection = compArrayCollection;

So I am setting the dataArrayCollection in my Comps component to the values
in my compArrayCollection in the main app.  What is weird though is that
whenever I change any values in the dataArrayCollection, they are also
changing back in my compArrayCollection back in the main app.  I don't want
this to happen, I want their values to be independent of one another once
the values are passed.  Is there any way to make this not happen?

Thanks,
Bill



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13662.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Rookie ArrayCollection Question

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

Helps if I read all the email.

Code wise I would just do this:

origArray = compArrayCollection.source;
for each(var o:Object in origArray) {
	o.newProperty = true;
}

> My compArrayCollection is populated by a PHP service and I think that is why
> I am having trouble with this.

Correct the object it creates in not dynamic, either change it to dynamic on the AS side or add the property the PHP side as well.

Thanks,
Justin

Re: Rookie ArrayCollection Question

Posted by bilbosax <wa...@comcast.net>.
If I understand correctly, your "addItem" method will only add a record to
the bottom of the arrayCollection, I don't believe that it will add a
property to the end of each record.  I am looking for something like this I
think, where compsArrayCollection is my original dataset:

var origArray:Array = new Array();
var newArray:Array = new Array();

origArray = compArrayCollection.source;
for each(var o:Object in origArray) {
	o.newProperty = true;
	newArray.push(o);
}
				
compArrayCollection.source = newArray;

My compArrayCollection is populated by a PHP service and I think that is why
I am having trouble with this.  I get the error:

Error #1056: Cannot create property newProperty on
valueObjects.CustomDatatype6

CustomDatatype6 was created during the service formation, and does not seem
to like me trying to add to any of its properties.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13651.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Rookie ArrayCollection Question

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

Is it possible to add the extra element when initially crating the 2D array collection. If the AC help a named object then all that would be required is adding a new property to that object.

> for(i=0; i<src.length; i++){
>    record = src.getItemAt(i) as ArrayCollection;
>    record.addItem( new MyElement() );
> }

Which it likely to be slow. to improve I’d:
- move src.length outside of loop
- access the array in the array collection rather than using getitemAt
- turn collection updates off while doing and refresh at end if you need bindings to fire

Thanks,
Justin



Re: Rookie ArrayCollection Question

Posted by Nemi <ne...@gmail.com>.
Lets say src is 2d collection, is this what you want:

var record:ArrayCollection;

for(i=0; i<src.length; i++){
    record = src.getItemAt(i) as ArrayCollection;
    record.addItem( new MyElement() );
}



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649p13650.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Rookie ArrayCollection Question

Posted by Matthew Weir <ma...@yahoo.com.INVALID>.
Do to only have access to the flex portion of the code?  Do you have the ability to manipulate the SQL or the web service?

Sent from Yahoo Mail on Android 
 
  On Wed, Sep 28, 2016 at 7:59 PM, bilbosax<wa...@comcast.net> wrote:   So I have a 2D ArrayCollection that has about 40k records in it with about 40
elements in each record.  I need to add an element or property to the end of
each record so that each record now contains 41 elements, but have no idea
how to do this.  Any suggestions?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Rookie-ArrayCollection-Question-tp13649.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.