문제

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