Access content of multi-dimensional array

I have an array created from an XML file (from a PHP script), that I pull into an arrayCollection using an HTTPService.

The XML file looks like this, and I'd like to filter on the value of cn0.

<record>
<cn0>Joe User</cn0>
<company0>Yahoo, Inc</company0>
<samaccountname0>joeuser1</samaccountname0>
</record>
<record>
<cn0>Jane User</cn0>
<telephonenumber0>+1 (888) 555-0800</telephonenumber0>
<company0>Yahoo, Inc</company0>
<samaccountname0>janeuser1</samaccountname0>
<mail0>user.jane@yinc.com</mail0>
</record>
..... and so on

My array is created as:
private var arrayListUsers:ArrayCollection=new ArrayCollection();
arrayListUsers = event.result.records.record as ArrayCollection;

I plan to filter for a string on *one* column of this array, using these functions:
private function fnFilterListUsers():void {
// Filters ListUsers
  arrayListUsers.filterFunction = fnSearch;
  arrayListUsers.refresh();
}
         
private function fnSearch(item:Object):Boolean {
  var colNos:int = arrayListUsers.length;
  for(var i:int=0;i<colNos;i++){
    if(item[arrayListUsers[i]] != null && item[arrayListUsers[i]].toString().toLowerCase().indexOf(txtSearch.text.toLowerCase()) != -1){
      return true;
    }
  }
    return false;
  }

I'm afraid arrayListUsers[i] is the incorrect method because I'm not specifying any columns in the array.  If I trace arrayListUsers[i] I simply see [object Object] for each row in my array.

Basically, how do I reference a particular column in a multi-dimension array, when the data is pulled from an XML file and I am not specifying the column names in the HTTPService or any other function?

Thanks!
LVL 4
wolfet410Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PluckaCommented:
arrayListUsers[x][y]
0
wolfet410Author Commented:
That's what I thought, but it doesn't work as I'd expect.

trace(arrayListUsers[0][0]); returns undefined
trace(arrayListUsers[1][1]); returns undefined

There should be data there.

In your example, does x = the column or the row?  Do columns start at 0 or 1?
0
PluckaCommented:
Are you using flex builder?

Put a break in and drill down on the variable and see what it looks like.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Aneesh ChopraCommented:
you should use "for..in"  loop to trace out object data

try this:

var total = arrayListUsers.length;
for(var i=0;i<total;i++)
{
      for(var n in arrayListUsers[i])
      {
            trace(arrayListUsers[i][n]);
      }
}
0
PluckaCommented:
@aneeshchopra

That wont change anything, arrayListUsers[0][0] should still exist, if infact this is an array.
0
Aneesh ChopraCommented:
use following class to trace out any objectwith 'n' level of object/arrays .. just copy and save it as "ObjectDumper3.as" into your project.

and use as following:

trace(ObjectDumper3.toString(arrayListUsers));
package
{ 
	import flash.xml.XMLNode;
	
	
	public class ObjectDumper3
	{	
		private static var inProgress;
		private static var maxLineLength = 100;
		private static var indent = 0;
		
		
		public static function sayHelloWorld():void
		{
			trace("helloWorld");
		};
		
		public static function toString(obj)
		{
			inProgress = new Array();
			return realToString(obj);
		}
		
		private static function realToString(obj)
		{
			inProgress.push(obj);
			
			var t = typeof(obj);
			var result;
			
			if ((obj is XMLNode))
			{
				result = obj.toString();
			}
			else if (obj is Date)
			{
				result = obj.toString();
			}
			else if (t == "object")
			{
				var nameList = new Array();
				if (obj is Array)
				{
					result = "["; // "Array" + ":";
					for (var i = 0; i < obj.length; i++)
					{
						nameList.push(i);
					}
				}
				else
				{
					result = "{"; // "Object" + ":";
					for (var q in obj)
					{
						nameList.push(q);
					}
					nameList.sort();
				}
					
				var sep = "";
				for (var j = 0; j < nameList.length; j++)
				{
					var val = obj[nameList[j]];
					
					var show = true;
					
					if (show)
					{
						result += sep;
						if (!(obj is Array))
							result += nameList[j] + ": ";
						result +=
							realToString(val);
						sep = ", `";
					}
				}
				
				
				if (obj is Array)
					result += "]";
				else
					result += "}";
			}
			else if (t == "function")
			{
				result = "function";
			}
			else if (t == "string")
			{
				result = "\"" + obj + "\"";
			}
			else
			{
				result = String(obj);
			}
			
			if (result == "undefined") result = "-";
			inProgress.pop();
			return replaceAll(result, "`", (result.length < maxLineLength) ? "" : ("\n" + doIndent(indent)));
		}
		
		
		private static function replaceAll (str : String, from: String, to: String)
		{
			var chunks = str.split(from);
			var result = "";
			var sep = "";
			for (var i = 0; i < chunks.length; i++)
			{
				result += sep + chunks[i];
				sep = to;
			}
			return result;
		}
		
		private static  function doIndent(indent)
		{
			var result = "";
			for (var i = 0; i < indent; i ++)
			{
				result += "     ";
			}
			return result;
		}
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wolfet410Author Commented:
Thanks for the code.
0
wolfet410Author Commented:
The answer to the question was:

arrayListUsers[n]['cn0']

The ActionScript gave me the information I needed to figure it out.

Thanks to both of you for the help.
0
Aneesh ChopraCommented:
welcome,

as per your final comment, my suggestion at comment ID:22873415  would have worked for you if you would have tried it..
0
wolfet410Author Commented:
Yes, that does work as well.  In your example, n is "cn0" (or whatever).  Because I misunderstood what "var n in arrayListUsers[i]" did, I figured n would be a number.  Since I already tried arrayListUsers[0][0], I skipped that test and went to the ActionScript code instead.  

I will use both methods in the future to find out exactly what is being stored in an array.

Thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.