Thank you - I have discovered the problem now - I was making a copy the XML for an asset when creating a list of items, which broke the indexing because the copy was not related to the original, e.g.

for (var i:int = 0; i < len;i++ ) {
    //Making a copy of the node means that getAssetDetails.
    var asset:XML = _assets[i].copy();
dp.addItem({label:asset.child("number") + ": " +asset.child("name"), data:asset.name});
}

Incidentally - the getAssetByNumber would not have been possible as I am programming to an API which compares objects of various types against the XML so I have to use getAssetDetails(prop:*)

Thank you for your help :)

Glen

On 17/02/2011 13:13, Jens Struwe wrote:
Thanks for the XML. Given this, the method works as expected:

getAssetByNumber(2001);
getAssetByNumber(2004);
getAssetByNumber(2007);

public function getAssetByNumber(theNumber : int):XML {
    if (!_assets) return null;
    var res : XMLList = _assets.*.(number == theNumber);
    if (0 != res.length()) {
        trace(this, "getAssetDetails " + XML(res[0]).childIndex());
        return res[0];
    } else {
        return null;
    }
}

-----

[object XMLTest] getAssetDetails 0
[object XMLTest] getAssetDetails 1
[object XMLTest] getAssetDetails 2



Am 17.02.2011 13:43, schrieb Glen Pike:
Hi,

The problem is not getting the assets - this works for both example
functions.

The problem is that when I try to trace the childIndex() of the asset
that has been found, it always returns -1 for the asset obtained by
matching the child rather than the attribute.

So the following e4x works, but the childIndex value does not.

var res:XMLList = _assets.(child("number") == String(prop));
if (0 != res.length()) {
debug(this, "getAssetDetails " + res[0].childIndex());
return res[0];
} else {
return null;
}

Here is a much shortened list of assets:

<entity>
<id>524</id>
<number>2001</number>
<name><![CDATA[Hello]]></name>
<description><![CDATA[Compose Audio]]></description>
<type>1</type>
<events_count>1</events_count>

<length>0.85</length>
<outputs>
</outputs>
</entity>
<entity>
<id>527</id>
<number>2004</number>

<name><![CDATA[Cry]]></name>
<description><![CDATA[Compose Audio]]></description>
<type>1</type>
<events_count>1</events_count>
<length>2.63</length>
<outputs>
</outputs>

</entity>
<entity>
<id>530</id>
<number>2007</number>
<name><![CDATA[Sob]]></name>
<description><![CDATA[Compose Audio]]></description>
<type>1</type>

<events_count>1</events_count>
<length>2.02</length>
<outputs>
</outputs>
</entity>

On 17/02/2011 12:30, Jens Struwe wrote:
May I refine your question?

"I have an XML tree. How can I select nodes depending on the value of
subnodes or the value of subnode attributes".

Hi,

I am having a problem with getting the childIndex value from an e4x
result:

Both these functions work - e.g. they return an XML node from a list,
but the childIndex property always traces as -1 for the first
function.

Can anyone see what the problem is?

TIA

Glen

public function getAssetDetails(prop:*):XML {
if (!_assets) {
return null;
}
var res:XMLList = _assets.(child("number") == String(prop));
if (0 != res.length()) {
debug(this, "getAssetDetails " + res[0].childIndex());
return res[0];
} else {
return null;
}
}

override public function getAssetDetails(prop:*):XML {
if (!_assets) {
return null;
}
var res:XMLList = _assets.(attribute("icon") == String(prop));
if (0 != res.length()) {
debug(this, "getAssetDetails " + res[0].childIndex());
return res[0];
} else {
return null;
}
}
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to