flex - Changes to one variable propagates to another -


For example, I have two ArrayCollection - first AC and IICAC. If I do secondAC = firstAC, and I make a second AAC change (already a filter function was applied to it) it is somehow used to propagate AAC first, would someone tell me that in Flex or ActionScript 3 Why does this happen

If I only want secondAC to get all the data from the first AAC, but then when I make changes to the second AAC, then I do not see it in AAC first?

Thanx a bunch for the answer! Ladislav

In ECMAScript languages ​​(AS1-3, JavaScript, et al.), When you use

  var foo = // Some values ​​which are not a string or a number  

What exactly are you saying "Fu now points to the same object It is the other variable. "This means that in this situation, both arrays will have the same values:

  var foo: array = [1, 2, 3]; Foo = bar; Bar Peash (4); Trace (fu); // 1, 2, 3, 4 also works for this function:  
  var foo: array = [1, 2, 3 ]; Copula (af); Function Joiner (Bar: Array): Zero {bar.push (4); } Trace (fu); // 1, 2, 3, 4  

and it also works with XML:

  var xml: XML = & lt; Root & gt; & Lt; Foo / & gt; & Lt; / Root> Var Bar: XML = xml; Bar.children () [0]. @ Bar = 1; Trace (xml.toXMLString ()); // & lt; Root & gt; & Lt; Foo bar = "1" /> & Lt; / Root & gt;  

It is called "passing by value" or "passing by reference" rather than "passing through copy". It means that every time the item is referenced, each variable will point to the same object.

There are several ways to come around this, and most of them depend on your reference. For arrays, my favorite is Array.concat (), which gives a literal clone of the array, which means that whatever I am doing at the returned value will not be basically influenced in any way. If I am working with XML, then I will do something like this: var xml2: XML = XML (xml.toXMLString ()); .

In your case, I would really recommend that you use it:

second second: ArrayCollection = new ArrayCollection (firstAC.source.concat ()); This is not only the main advantage of fast moving (this flex depends on the compiled code instead of the SDK code and it does not first instantize a new array and then it again Fills), but there is also a special advantage of being available in earlier versions of the Flex 3 SDK - it is completely compatible.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -