0
votes

I have trouble with ArrayCollection in Flex. Here is my code:

 private var productPageArr:ArrayCollection;
 private var productCount:Number = 10;

 private function dviceProductPage(arr1:ArrayCollection,arr2:ArrayCollection):ArrayCollection       
 {      
    var page:Number = arr1.length      //productCount; 
    var i:int;
    arr2 = new ArrayCollection();

    //productPageArr = new ArrayCollection();

    for(i = 0; i<page; i++)
    {
      var o:Object = new Object();
      o.label = String(i+1);
      arr2.addItem(o);  
    }

    //arr2.refresh();
    return arr2;
 }

When I run this block of code, my application is terminated. But when productPageArr is replaced with arr2 then my application runs smoothly.

1
//productPageArr = new ArrayCollection(); <- is this the code that crashes it, when uncommented? I mean, where and what do you replace exactly?Jonatan Hedborg
Is this the code that runs smoothly or the code that crashes?Chad

1 Answers

0
votes

The problem is around the use of "arr2". "arr2" is an argument to your function, which may not be accessible from here.

I can't really tell what you are trying to achieve but my suggestion is to create a new variable within your function which you can safely return as the result of your function (which leaves the question as to why you are accepting "arr2" as an argument at all).

I hope this helps.

 private var productPageArr:ArrayCollection;
 private var productCount:Number = 10;

 private function dviceProductPage(arr1:ArrayCollection,arr2:ArrayCollection):ArrayCollection       
 {      
    var page:Number = arr1.length      //productCount; 
    var i:int;
    var arr3 = new ArrayCollection();

    for(i = 0; i<page; i++)
    {
      var o:Object = new Object();
      o.label = String(i+1);
      arr3.addItem(o);  
    }

    return arr3;
 }