item.mediums = new Array();


Should be fine, however:

item.mediums[item.mediums.length]['id'] = m[i_m].attributes.id;


Looks like you're trying to access a 2D array or Object in array, so you
would have to do something like:

var medium:Object = new Object();
medium.id = m[i_m].attributes.id;
medium.name = m[i_m].firstChild.firstChild.nodeValue;
.
.
item.mediums.push( medium );

This doesn't mean that what you're doing is necessarily a best practice, but
I'm not sure what your motivation is to do so. If you simply want to access
xml as a more manageable data object, you can use things like XPath or
Xml2Object(?).

-Scott

On 12/28/06, Mike Dunlop <[EMAIL PROTECTED]> wrote:

Hi gang,

I'm having difficulty parsing an xml file into a multidimensional
array and was wondering if anyone could see why the following isn't
working... My guess is that an object variable can't be an array?



XML Sample
----------------------------------------------------------------------

<list>
        <cat id="4">
                <name>Art Glass</name>
                <notes></notes>
                <mediums>
                        <medium id="18">
                                <name>Drypoint</name>
                                <notes></notes>
                                <img>media/18_medium_tn.jpg</img>
                        </medium>
                </mediums>
        </cat>
</list>

----------------------------------------------------------------------


Actionscript
----------------------------------------------------------------------


        var arr:Array = xml.firstChild.childNodes;

        for(var i:Number = 0; i < arr.length; i++) {
                var item:Object = new Object();
                item.id = arr[i].attributes.id;
                item.name = arr[i].firstChild.firstChild.nodeValue;
                item.notes =
arr[i].firstChild.nextSibling.firstChild.nodeValue;

                /***** this part isn't working *******/
                item.mediums = new Array();
                if(arr[i].firstChild.nextSibling.nextSibling.hasChildNodes())
{
                        var m:Array =
arr[i].firstChild.nextSibling.nextSibling.childNodes;
                        for(var i_m:Number = 0; i_m < m.length; i_m++) {
                                item.mediums[item.mediums.length]['id'] =
m[i_m].attributes.id;
                                item.mediums[item.mediums.length]['name']
= m
[i_m].firstChild.firstChild.nodeValue;
                                item.mediums[item.mediums.length]['notes']
= m
[i_m].firstChild.nextSibling.firstChild.nodeValue;
                                item.mediums[item.mediums.length]['img'] =
m
[i_m].firstChild.nextSibling.nextSibling.firstChild.nodeValue;
                        }
                }
                /***** /this part isn't working *******/
        }

----------------------------------------------------------------------


Thanks for your help guys!

Best,
Mike D


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com




--

: : ) Scott
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to