Thanks so much Jens!
Willem van den Goorbergh
On 16 feb 2011, at 14:33, Jens Struwe wrote:
> To recusively dump your complex object you might use:
>
> function traceProperties(object : Object, depth : uint = 0) : void {
> for (var prop : String in object) {
> trace (prefix(depth), prop, object[prop]);
> if (object[prop] is Object) traceProperties(object[prop], depth + 1);
> }
>
> function prefix(depth : uint) : String {
> var prefix : String = "";
> for (var i : uint = 0; i < depth; i++) prefix += "....";
> return prefix;
> }
> }
>
> Anyway, there is also an error in createProperties. Look at the attached test
> file to compare with my fixes. Hope the list allows me to pass files.
>
> map [object Object]
> ....classes [object Object]
> ........class2 [object Object]
> ............value RA02
> ............areaColor 0xFFFFFF
> ............keyText Noord-Nederland2
> ........class1 [object Object]
> ............value RA01
> ............areaColor 0xEBDBAA
> ............keyText Noord-Nederland
> ....subTitle k
> ....layers [object Object]
> ........gemeenteNaam [object Object]
> ............visible false
> ............title [object Object]
> ................nl gemeentenamen
>
> Best,
>
> Jens
>
> Am 16.02.2011 13:29, schrieb Geografiek:
>> Hi Jens,
>> What I basically want is to transform the xml structure into an object
>> structure.
>> xml:
>> <map id="gemRegioIndeling">
>> <subTitle></subTitle>
>> <classes>
>> <class1>
>> <areaColor>0xEBDBAA</areaColor>
>> <keyText><![CDATA[Noord-Nederland]]></keyText>
>> <value>RA01</value>
>> </class1>
>> <class2>
>> <areaColor>0xEBDBAA</areaColor>
>> <keyText><![CDATA[Noord-Nederland]]></keyText>
>> <value>RA01</value>
>> </class2>
>> <layers>
>> <gemeenteNaam>
>> <visible>false</visible>
>> <title>
>> <nl><![CDATA[gemeentenamen]]></nl>
>> </title>
>> </gemeenteNaam>
>> </layers>
>> </map>
>>
>> flash object:
>> map
>> map.classes
>> map.classes,class1
>> map.classes,class1.areaColor
>> map.classes,class1.value
>> ...
>> map.classes,class2
>> map.classes,class2.areaColor
>> map.classes,class2.value
>> ...
>> ...
>> ...
>> map.layers
>> ...
>> ...
>> ...
>>
>> Things seem to work, but I want to traverse the properties tree of the flash
>> object and can't get that part working.
>> Thanks,
>> Willem van den Goorbergh
>>
>> On 16 feb 2011, at 13:10, Jens Struwe wrote:
>>
>>> Having an example XML could be pretty useful.
>>>
>>> And, actually, I don't understand the problem. What should be the output?
>>> Please hand over all necessary info required to be able to help you.
>>>
>>> Am 16.02.2011 12:43, schrieb Geografiek:
>>>> Hi list,
>>>> I posted this question a week ago on flash tiger, but never got an answer.
>>>> So I try my luck here.
>>>>
>>>> I create an object and dynamically assign properties to it, values from
>>>> xml-nodes.
>>>> If an xml-node has child nodes the property assigned is an object and the
>>>> values of the child nodes are assigned as properties to that object:
>>>>
>>>> private function createProperties(node:XML, container:*):void {
>>>> for each (var childNode:XML in node.*) {
>>>> if(childNode.children().length() == 0) {
>>>> container[childNode.localName()] = null;
>>>> } else if(childNode.children().length() == 1) {
>>>> container[childNode.localName()] = childNode.*;
>>>> } else {
>>>> container[childNode.localName()] = new Object();
>>>> createProperties(childNode, container[childNode.localName()]);
>>>> }
>>>> }
>>>> }
>>>>
>>>> Now I want to trace what properties are created with the following
>>>> function:
>>>> private function traceProperties(object:Object):void {
>>>> for (var prop:* in object) {
>>>> trace(prop + " is: " + object[prop]);
>>>> traceProperties(prop);
>>>> }
>>>> if(object.hasOwnProperty("layers")) {
>>>> trace("this.layers.gemeenteNaam.title is: " +
>>>> this.layers.gemeenteNaam.title);
>>>> trace("this.classes.class1.keyText is: " +
>>>> this.classes.class1.keyText);
>>>> }
>>>> }
>>>>
>>>> This traces:
>>>> source is: null
>>>> note is: null
>>>> subTitle is: null
>>>> copyright is: Geografiek, 2011
>>>> mapType is: chorochromaat
>>>> classes is: [object Object]
>>>> key is: [object Object]
>>>> layers is: [object Object]
>>>> this.layers.gemeenteNaam.title is: gemeentenamen
>>>> this.classes.class1.keyText is: Noord-Nederland
>>>>
>>>>> From this I gather that all properties are actually created on their
>>>>> desired level (last 2 traced lines).
>>>> But the function traceProperties() does not automatically catch all
>>>> properties. At least not the properies inside the objects
>>>> How do I check if an object has properties at all and how do I trace them?
>>>> TIA
>>>> Willem van den Goorbergh
>>>>
>>>> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
>>>> Geografiek is a Dutch, Utrecht-based map and chart design company.
>>>> Willem van den Goorbergh can be contacted by telephone: (+31)30-2719512 or
>>>> cell phone: (+31)6-26372378
>>>> or by fax: (+31)302719687
>>>> snail mail: Hooghiemstraplein 89 3514 AX UTRECHT
>>>> Visit our website at: www.geografiek.nl
>>>> twitter: @wvdgoorbergh
>>>> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Flashcoders mailing list
>>>> [email protected]
>>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>>
>>>
>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
>> Geografiek is a Dutch, Utrecht-based map and chart design company.
>> Willem van den Goorbergh can be contacted by telephone: (+31)30-2719512 or
>> cell phone: (+31)6-26372378
>> or by fax: (+31)302719687
>> snail mail: Hooghiemstraplein 89 3514 AX UTRECHT
>> Visit our website at: www.geografiek.nl
>> twitter: @wvdgoorbergh
>> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
>>
>>
>>
>>
>>
>> _______________________________________________
>> Flashcoders mailing list
>> [email protected]
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
>
> <XMLTest.as>_______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
Geografiek is een in Utrecht gevestigd kartografisch bureau
Willem van den Goorbergh is telefonisch bereikbaar onder nummer 030-2719512
of mobiel: 06-26372378
Per fax is Geografiek bereikbaar onder nummer: 030-2719687
postadres: Hooghiemstraplein 89 3514 AX UTRECHT
Bezoek onze website op: www.geografiek.nl
twitter: @wvdgoorbergh
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders