4 Replies Latest reply on Jan 17, 2010 10:00 AM by Pierpaolo Bertalotto

    e4x conditional node selection

    Pierpaolo Bertalotto

      Hi guys! I'm having a huge problem with e4x conditional node selection. My project is big, with tens of components, interfaces and stuff, therefore don't ask me to post code... In one of these components, which works as a tree item editor, conditional selection doesn't work at all. If I try to select a node list by using the name of the nodes I'm interested in, such as "classHierarchy..Individual", everything goes as expected. However when I try to add a conditional to the quoted line, in order to select a specific XML node, I always get a null object, although I'm sure that the node I'm trying to select actually exists in the scope of the expression. Does anybody have any idea of why this is happening? I repeat: everywhere else in my application this kind of syntax, also with much more complex expressions including namespaces and stuff, does work fine. I really can't get what is different in this component...

        • 1. Re: e4x conditional node selection
          _Natasha_ Level 4

          Can you post an example for XML and code for selecting node form it?

          • 2. Re: e4x conditional node selection
            Pierpaolo Bertalotto Level 1

            Thanks for your answer! The following is a very simple example of the XML a user would have i a standard situation (it is generated at runtime):


            <Classes label='Thing'>

                 <Class label="Geographical Location">

                      <Class label="City">

                           <Individual label="Rome"/>


                      <Class label="Region">

                           <Individual label="Land of Israel"/>





            Now, let's assume that I want to select the "Class" node of the "Individual" whose label is "Rome". One way to do this by using e4x in as3 is:


            var individualClass:XML = myXML..Individual.(@label == 'Rome')[0].parent();


            I put the double dot ".." after myXML because I don't know at what level the individual I'm trying to select is going to be. Anyway, this kind of syntax works correctly everywhere in my application but in a component. I checked everything I could think of. What I'va noticed is that apparently no kind of condition in parenthesis would work. If I write for instance:


            var individualClasses:XMLList = myXML..Individual;


            it correctly returns an XMLList containing all the "Individual" nodes. Any node in the XMLList is the selectable by specifing the node position by using the array-like syntax ("[n]"). However, as soon as I put a condition in parenthesis the command returns a null object, whatever the condition. There must be a reason why this is happening, but I just can't think to anything besides what I have alredy tryed. I already have a workaround for this, but I'm very courious to know what is going on here.

            • 3. Re: e4x conditional node selection
              _Natasha_ Level 4

              Check if all Individual nodes has label property.

              All properties used if e4x conditions should be in all nodes.

              • 4. Re: e4x conditional node selection
                Pierpaolo Bertalotto Level 1

                yes, they do, no doubt on this. And, by the way, if they didn't, Flex would have fired an error, which is not the case. The mystery gets darker and darker...