質問

I've been using E4X expressions and it has never caused a problem. Today I got this error which is driving me crazy. Checked everything thousand times, searched web, but nothing.

So this is my query for the value:

var objectName:String = myXML.objects.object.(@id==objectId);

where objectId is an int.

This is the part of my XML:

<objects>

    <object id="0">value 1</object>
    <object id="1">value 2</object>
    <object id="2">value 3</object>

</objects>

When the above line is run I get an error which seems like a total nonsense to me:

ReferenceError: Error #1065: Variable id is not defined.
役に立ちましたか?

解決

It's because not all of your object nodes has the id attribute, try more safety way to search through the attributes with hasOwnProperty("@id") checks:

    var objectName:String = 
        xml.objects.object.(hasOwnProperty("@id") && @id=="2");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top