So if I understand it correctly u have a series of events. If u would
convert this xml to and object u would have something like this:
event[0].month = "04";
event[0].day = "14";
event[0].short = "heckey";
event[0].description = "bla";
Now u want to get access to all events on a certain day in a certain
month like this
myObject["04"]["14"][0].short = "hockey";
myObject["04"]["14"][0].description = "bla";
In order to be able to do that u need to convert your initial data, u
can do that like this:
/*
input:
events_array
[0]
month
day
short
description
[1]
...
output:
object
[month_str]
[day_str]
[0]
short
description
[1]
...
[day_str]
...
[month_str]
...
*/
public function convertData(events_array:Array):Object
{
var obj:Object = new Object();
var length_num:Number = events_array.length;
while (length_num--)
{
var currentEvent_obj:Object = events_array[length_num];
var month_str:String = currentEvent_obj.month;
var day_str:String = currentEvent_obj.day;
var month_obj:Object = obj[month_str];
if (!month_obj)
{
month_obj = myObject_obj[month_str] =
new Object();
};
var day_array:Array = month_obj[day_str];
if (!day_array)
{
day_array = month_obj[day_str] = new Array();
};
day_array.push({short: currentEvent_obj.short,
description:
currentEvent_obj.description});
};
return obj;
};
Greetz Erik
-----Original Message-----
From: heybluez [mailto:[EMAIL PROTECTED]
Sent: donderdag 7 april 2005 14:52
To: [email protected]
Subject: [flexcoders] Associative Arrays / "Hashes"
I am trying to see if I can get an array to be more like a hash...
what i mean is say I have the following:
<node>
<events>
<month>04</month>
<day>14</day>
<short>hockey</short>
<description>blah</description>
</events>
<events>
<month>04</month>
<day>14</day>
<short>reading</short>
<description>blah</description>
</events>
<events>
<month>04</month>
<day>14</day>
<short>baseball</short>
<description>blah</description>
</events>
<node>
I want to loop through that and produce something like this...
myObject[<month>][<day>]=Array(of Objects for that day);
so I could just do a myObject[<month>][<day>] and get back an array of
objects of those events.
First, does this make sense and two how would I do this in AS?
Thanks,
Michael
Yahoo! Groups Links
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/