1

I'm using a parent to pass a multi-dimensional array to a child. Structure of the array, named projectPositions is as follows (with example data):

projectPositions[0][0] = 1;
projectPositions[0][1] = 5;
projectPositions[0][2] = '1AD';
projectPositions[0][3] = 'User name';

I need to take this inherited array and turn it into an arrayCollection so that I can use it as a dataProvider. Currently, my init function (which runs onCreationComplete) has this code in it to handle this task of array -> arrayCollection:

for (var i:int = 0; i < projectPositions.length; i++)
{
tempObject = new Object;
tempObject.startOffset = projectPositions[i][0];
tempObject.numDays = projectPositions[i][1];
tempObject.role = projectPositions[i][2];
tempObject.student = projectPositions[i][3];
positionsAC.addItemAt(tempObject, positionsAC.length);
}

Then, during a repeater, I use positionsAC as the dataprovider and reference the items in the following way:

<mx:Repeater id="indPositions" dataProvider="{positionsAC}" startingIndex="0" count="{projectPositions.length}">
    <components:block id="thisBlock" offSet="{indPositions.currentItem.startOffset}" numDays="{indPositions.currentItem.numDays}" position="{indPositions.currentItem.role}" sName="{indPositions.currentItem.student}" />
</mx:Repeater>

This all works fine and returns the desired effect, but the load time of this application is around 10 seconds. I'm 99% sure that the load time is caused by the array -> arrayCollection for loop. Is there an easier way to achieve the desired effect without having to wait so long for the page to load?

Brds
  • 1,035
  • 3
  • 17
  • 37

2 Answers2

1

The issue your having loading items could be because you are using a repeater instead of a list class.

With a repeater, there will be a block created in memory, and drawn on the screen. So, if you have 100 items in your array, then 100 blocks will be created. this could slow down both initial creation and the overall app.

A list based class focuses on a technique called renderer recycling; which means only the displayed elements are created and rendered on the screen. So, depending on settings, you'd usually have 7-10 'block' instances on the screen, no matter how many items you have in your array.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
0

change

positionsAC.addItemAt(tempObject, positionsAC.length);

to

positionsAC.addItem(tempObject);

addItemAt is causing a reindex of the collection which can greatly slow down the collection.

[EDIT] Put this trace statement before and after the loop take the output and subtract one from the other and that will show how many milliseconds the loop has run.

var date:Date = new Date( );
trace( date.getTime())
The_asMan
  • 6,364
  • 4
  • 23
  • 34