Error #1010: A term is undefined

I keep getting this error in this function:


		private function search(e:Event):void
		{
			if (searchtxt.text)
			{
				searchResults_ar.splice(0);
				var searchCriteria:String = searchtxt.text.toLowerCase();
				for (var i:int = 0; i< searchStrings_ar.length; i++)
				{
					var index = searchStrings_ar*.toLowerCase().indexOf(searchCriteria);
					if (index > -1)
					{
						searchResults_ar.push(i + 1);
					}
				}
				if (searchResults_ar.length != 0)
				{
					// Clear the list component
					slideList.removeAll();
					for (var k:int = 0; k < searchResults_ar.length; k++)
					{
						var j = searchResults_ar[k];
						var slideTitle = xmlList[j].Title;
						var slideID = xmlList[j].@id;
						slideList.addItem({label:j + ". " + slideTitle, data:slideID});
					}
				}
				else
				{
					trace("nothing found");
				}
			}
		}


and I cannot figure it out! Everything compiles fine, the function even works the way it is suppose to, but every time I hit my search button, I get this error:


TypeError: Error #1010: A term is undefined and has no properties.
	at Vforum/::search()

Do you guys see anything that might be causing this?

It’s hard to tell bc you are referencing other variables from outside this function, but one theory of mine is that you are referencing an empty index in one of your arrays.

ok then I will try tracing back some values and see what comes up!

Turn on ‘permit debugging’ under your publish settings and it’ll tell you exactly which line is throwing the error.

ok Ive pinpointed it to my second if statement in that function because if I comment it out, the error disappears. The problem is everything is tracing out just fine…


				if (searchResults_ar.length != 0)
				{
					// Clear the list component
					slideList.removeAll();
					for (var k:int = 0; k < searchResults_ar.length; k++)
					{
						var j = searchResults_ar[k];
						var slideTitle = xmlList[j].Title;
						var slideID = xmlList[j].@id;
						trace(j + " = " + slideTitle + " & slideID = " + slideID);
						slideList.addItem({label:j + ". " + slideTitle, data:slideID});
					}
				}

and the output is:


1 = What is CANES? & slideID = 2
2 = Capability Discussion & slideID = 3
3 = CANES Operational Benefits & slideID = 4
4 = Increased War Fighter Network Capabilities & slideID = 5
6 = Legacy vs. CANES CDD Objective / Threshold Capabilities & slideID = 7
7 = Overall Schedule & slideID = 8
9 = Fleet Introduction & slideID = 10
10 = CANES and the Early Adopter Process & slideID = 11
11 = Early Adopters (EA) and the Migration to CANES & slideID = 12
12 = Summary & slideID = 13
TypeError: Error #1010: A term is undefined and has no properties.
	at Vforum/::search()

oh thanks Anogar…it says the error is on line 142 which is pointing to


	var slideTitle = xmlList[j].Title;

It isnt undefined though because it traces out just fine…hmm weird…

You’re probably looping too far. Try k < searchResults_ar.length - 1.

[QUOTE=Anogar;2351564]You’re probably looping too far. Try k < searchResults_ar.length - 1.[/QUOTE]

hah well that was it. Nice job and thank you!

You’ll get my invoice by mail. :wink:

hey dude…ok I am running into a small issue. When I hit my search button and say it only finds one result, it doesnt display it. If I take out the -1 I added yesterday it shows up, but then that stupid error comes up again. Am I using the wrong operator maybe? Rather than < do <= maybe??

It shouldn’t really matter. Try debugging it by putting a more concrete number in there - like 5 or something.

well I just did a little work around…messy but it works.


if (searchResults_ar.length != 0)
{
	slideList.removeAll();
	var searchLength:int;
	if (searchResults_ar.length == 1)
	{
		searchLength = searchResults_ar.length;
	}
	else
	{
		searchLength = searchResults_ar.length - 1;
	}
	for (var k:int = 0; k < searchLength; k++)
	{
		var j:int = searchResults_ar[k];
		var slideTitle = xmlList[j].Title;
		var slideID = xmlList[j].@id;
		slideList.addItem({label:j + ". " + slideTitle, data:slideID});
	}

	reloadBtn.addEventListener(MouseEvent.CLICK, resetSlideList);
	reloadBtn.buttonMode = true;
	reloadBtn.useHandCursor = true;
}
else
{
	trace("nothing found");
}


Wasn’t sure what else to do. I am writing this thing as a class and so far it looks like just one big procedural script done in an AS file, granted applying private, public, const etc…

I cant grasp the idea of classes I guess…been trying for awhile.

That doesn’t look right at all. First off, you should never NEED to do length-1 in a loop like that. It looks to me like your xml is invalid somehow.

[QUOTE=sekasi;2352049]That doesn’t look right at all. First off, you should never NEED to do length-1 in a loop like that. It looks to me like your xml is invalid somehow.[/QUOTE]

The xml is fine:
http://ronnieswietek.com/presentation.xml

view the source to see because you are obviously going to get an error if you have FF or IE format it because of chars like & etc…