PDA

View Full Version : 16k+ elements in Array.addItem = stalling


tallone2
02-16-2006, 08:13 PM
spent the last 30 mins searching the boards for an answer to this ...

I'm loading 16000+ records into an array and an i want to provide the user with an indication that something is actually going on. I was hoping to use the ProgressBar and every 100 or so records update the label of the progress bar. Well with the For loop loading into the array nothing happens till its done - so i tried splitting the returned results up and using 2 for loops - a paging type thing. And trying to do a progress bar update between them - call a function - or what ever and nothing is working.

here is a snip of code


aspResponse = unescape(this);
rsArray = aspResponse.split("|");
//remove last element in array - onload function
rsArray.splice(rsArray.length-1, 1);
var maxPage:Number = 0;
var perPage:Number = 100;
var maxIndex = rsArray.length;
var index:Number = 0;
pBar.minimum = 100;
pBar.maximum = maxIndex;
pBar.label = "%1 of %2";
maxPage = Math.round(rsArray.length/perPage)+1;
for (var cPage:Number = 0; cPage<maxPage; cPage++) {
for (var pageIndex:Number = 0; pageIndex<perPage; pageIndex++) {
if (index<rsArray.length) {
recArray = rsArray[index].split("~");
_owner.wellListDP.addItem({label:recArray[0], data:{Index:index, FileNumber:recArray[0], Api:recArray[1], Con:((recArray[2] == "True") ? true : false)}});
if (recArray[2] == "True") {
_owner.configPanel_mc.dataType_list.setPropertiesA t(index, {backgroundColor:0xFF0000});
}
index++;
}
}
pBar.setProgress(index, maxIndex);
//trace('cPage='+cPage+' index='+index+' #='+maxIndex);
}
pBar.visible = false;
_owner.configPanel_mc.dataType_list.dataProvider = _owner.wellListDP;


i've also looked into updateAfterEvent, and setInterval but cannot manage to mesh them with the functionality i want.

any suggestions would be super.

thanks

tallone2
02-17-2006, 04:31 PM
well i kind of have something working with intervals. here is what i managed to get working.

private function initialize():Void {
if (viewConfidential) {
aspPath = aspPath+"methods/";
}
var _owner:ProductionCurve = this;
var httpString:String = aspPath+"declineCurveApp.asp";
var initResults:LoadVars = new LoadVars();
var initSend:LoadVars = new LoadVars();
var aspResponse:String = "";
var rsArray:Array = new Array();
var recArray:Array = new Array();
var pBar:ProgressBar = _owner.configPanel_mc.data_pBar;
pBar.visible = true;
pBar.indeterminate = true;
pBar.mode = "manual";
initResults.onLoad = function(success:Boolean) {
if (success) {
aspResponse = unescape(this);
rsArray = aspResponse.split("|");
//remove last element in array - onload function
rsArray.splice(rsArray.length-1, 1);
_owner.recordSet = rsArray;
switch (_owner.dQueryType) {
case "well" :
_owner.startLoadWells();
break;
case "field" :
_owner.startLoadFields();
break;
case "unit" :
_owner.startLoadUnits();
break;
default :
_owner.startLoadWells();
}
} else {
trace(this.toString());
trace("Error loading/parsing");
}
};
if ((dQueryType.length>0) && (dQueryValue.length>0)) {
// Do load well / field / unit based on passed vars
switch (dQueryType) {
case "well" :
pBar.label = "Getting Wells";
initSend.method = "getWells";
break;
case "field" :
pBar.label = "Getting Fields";
initSend.method = "getFields";
break;
case "unit" :
pBar.label = "Getting Units";
initSend.method = "getUnits";
break;
default :
pBar.label = "Getting Wells";
initSend.method = "getWells";
}
} else {
// initialize and load well data by default
pBar.label = "Getting Wells";
initSend.method = "getWells";
}
initSend.sendAndLoad(httpString, initResults, "POST");
}
private function startLoadWells():Void {
var pBar:ProgressBar = configPanel_mc.data_pBar;
pBar.label = "Loading Wells";
maxWellIndex = recordSet.length;
numWellPages = Math.round(maxWellIndex/wellPageAmount);
if (wellIntervalID != null) {
clearInterval(wellIntervalID);
}
wellIntervalID = setInterval(this, "updateWellList", 125);
pBar.minimum = 0;
pBar.maximum = maxWellIndex;
}
private function updateWellList():Void {
var pBar:ProgressBar = configPanel_mc.data_pBar;
var recArray:Array = new Array();
var endValue:Number = curWellIndex+wellPageAmount;
for (var index:Number = curWellIndex; index<endValue; index++) {
if (index<maxWellIndex) {
recArray = recordSet[index].split("~");
wellListDP.addItem({label:recArray[0], data:{Index:index, FileNumber:recArray[0], Api:recArray[1], Con:((recArray[2] == "True") ? true : false)}});
curWellIndex++;
}
}
if (curWellIndex == maxWellIndex) {
clearInterval(wellIntervalID);
pushDP();
}
pBar.setProgress(curWellIndex, maxWellIndex);
pBar.label = "%1 of "+maxWellIndex;
}
function pushDP() {
var pBar:ProgressBar = configPanel_mc.data_pBar;
configPanel_mc.dataType_list.dataProvider = wellListDP;
if (viewConfidential) {
for (var x:Number = 0; x<wellListDP.length; x++) {
if (wellListDP[x].data.Con) {
configPanel_mc.dataType_list.setPropertiesAt(x, {backgroundColor:0xFF0000});
}
}
}
pBar.visible = false;
recordSet = new Array();
}

Now this works really well when running through the For Loop to populate the array with the data from an asp page. But i was wondering, i havent seen a way to do a preloader for data getting kicked out via LoadVars (loading asp strings). So this 16000+ records getting sent over the internet is downloading okay, but its not all the info i need to return (probably another 4-8 more fields, easily tripling the size).

Has anyone attempted to using a paging process for loading data into an array? would this be worse then just makeing the user wait till the entire LoadVars is downloaded (with out any form of animation / screen indicator).

kind of a data streamer with out the back end stuff i guess - with the flash client in control of fetching.

just thinking out loud, anyone else have suggestions?

thanks