Script locking/freezing my browser...Please Help

i’m running into a situation.
what i have are two datagrids named “dgList” and “dgCarFind”; they both display make and models of vehicles.

with great help from a moderator of another forum he/she was able to provide with me a working script that allowed me to
select a cell of dgCarFind and it will cycle through all of the cells of dgList just to output whether or not a match was found.

here is the original script below.


///////////////////////my_dg///////////////////////////////

var myDP:Array = new Array ();
myDP.addItem ({id:1, firstName:"firstName_1", lastName:"lastName_1"});
myDP.addItem ({id:2, firstName:"firstName_2", lastName:"lastName_2"});
myDP.addItem ({id:3, firstName:"firstName_3", lastName:"lastName_3"});
myDP.addItem ({id:4, firstName:"firstName_4", lastName:"lastName_4"});
my_dg.dataProvider = myDP;

///////////////////////my_dg2///////////////////////////////

var myDP2:Array = new Array ();
myDP2.addItem ({id:1, firstName:"firstName_1", lastName:"lastName_1"});
myDP2.addItem ({id:2, firstName:"firstName_2", lastName:"lastName_2"});
myDP2.addItem ({id:3, firstName:"firstName_3", lastName:"lastName_3"});
myDP2.addItem ({id:4, firstName:"firstName_5", lastName:"lastName_5"});
my_dg2.dataProvider = myDP2;

var dg2:Object = new Object ();
dg2.cellPress = function (evt:Object) {
var match2 = false;
var tmp2 = evt.target.columns[evt.columnIndex].columnName;
var searchVal2 = evt.target.getItemAt(evt.itemIndex)[tmp2];
for(var n=0;n!=myDP.length;n++){
if(searchVal2 == myDP[n].firstName || searchVal2 == myDP[n].lastName){
match2 = true; break; } else { match2 = false; }
}
match2 ? trace("match found") : trace("no match");
};
my_dg2.addEventListener ("cellPress",dg2);

in other words for example if dgList had these vehicles populated in the datagrid:
make: honda model: accord
make: toyota model: camry
make: bmw model: m3

and dgCarSearch had the vehicles populated in the datagrid
make: honda model: accord
make: toyota model: camry
make: bmw model: m5

so in the event where one would select either the cell of honda, accord, toyota, camry and bmw, the script would return the value of true, “match found”. but if you noticed that the the bmw’s model do not match, the script would return false…“no match found”.

here is how my current environment is set up:
again, i have two datagrids.

the first datagrid named “dgList” gets populated from vars loaded via php via mysql:


var sendData:LoadVars = new LoadVars ();
var r_string:LoadVars = new LoadVars ();

sendData.sendAndLoad ("cars_datagrid.php", r_string,"POST");
r_string.onLoad = getResponse;

function getResponse (result) {
	if (result == true) {
		var r_string:Array = new Array ();
		for (var i:Number = 0; i < this.n; i++) {
			r_string.push ({cust_id_num:this["cust_id_num" + i], carMakeCol:this["sql_make" + i], carModelCol:this["sql_model" + i]});
		}
	}
	dgList.dataProvider = r_string;
}

the way these columns are created is by this:


var carMakeCol:DataGridColumn = new DataGridColumn ("carMakeCol");
carMakeCol.headerText = "Make";
carMakeCol.width = 60;
dgList.addColumn (carMakeCol);

var carModelCol:DataGridColumn = new DataGridColumn ("carModelCol");
carModelCol.headerText = "Model";
carModelCol.width = 110;
dgList.addColumn (carModelCol);

…the column creation process is nearly identical except for the datagridcolumn var.
the cust_id_num column i choose not to display in the datagrid.

the second datagrid is called “dgCarFind” and would like it so that when you press on a either the make or model cell it will output true if it’s found or the opposite if not.
what i did with your code was that i suited it for my current environment like so:


var dgSearch:Object = new Object ();
dgSearch.cellPress = function (evt:Object) {
	output.text = "";
	var match = false;
	var tmp = evt.target.columns[evt.columnIndex].columnName;
	var searchVal = evt.target.getItemAt (evt.itemIndex)[tmp];
	for (var n = 0; n != r_string.length; n++) {
		if (searchVal == r_string["sql_make" + n] || searchVal == r_string["sql_model" + n]) {
			match = true;
			output.text = match;
			break;
		} else {
			match = false;
		}
	}
	match ? trace ("match found") : trace ("no match");
	
};
dgCarFind.addEventListener ("cellPress",dgSearch);

though it works if it finds a match, it freezes my browser if a match is not found and gives me the error:
a script in this movie is causing flash to run slowly…would you like to continue this script…yes…no”.

i’ve even tried changing the conditional operator from != to < and i’m still experiencing this problem of freezing/locking up.

i know that if i were to trace out r_string[“sql_make” + n] or r_string[“sql_model” + n] they will output the string of the what is being stored in that particular cell…same goes for searchVal.
any ideas as to why this is happening? :confused:

any help on will greatly appreciated.