Flash CS4 bug with XML E4X filters

| 1 min read

I had some XML E4X filters and I couldn't understand why they were working everywhere (included Gumbo) but in the Flash CS4 IDE.

I've finally isolated the problem…

I’ve got a simple XML like this:

<?xml version="1.0" encoding="utf-8"?>
<item id="item1" type="item1_type" />
<item id="item2" type="item2_type">
<item id="item3" type="item3_type" />

Basically my filter is parsing all the attributes "id" of the nodes "item", to return me the attribute "type", sounds simple.

Here is my filter:

xml..*.(name() == "item" && @id == "item1").@type

So, I nicely put this filter in a function, and then it stopped working in Flash CS4. When I tried to get the type of the id "item1" it worked but none of the id "item2" and "item3" worked, the filter wasn’t able to find the node. Also, when I removed the item3, which is a child of the item2, I could get the type of my item2… how weird, anyway…

My mistake, which wasn’t really a mistake by the way, was to use the word "item" as a parameter of my function. It should work as the parameter has nothing to do with the XML but it seems that Flash CS4 messed up with something and got lost.

So, this didn’t work:

 getItemTypeNotWorking("item2"); function getItemTypeNotWorking(item:String):void { trace("test1 = ", xml..\*.(name() == "item" && @id == item).@type); } 

But this worked:

 getItemTypeWorking("item2"); function getItemTypeWorking(itemID:String):void { trace("test2 = ", xml..\*.(name() == "item" && @id == itemID).@type); } 

As you can see only the parameter is different (item and itemID).

Using a parameter that is the same word as a node name will make the filter not working as intended, only in Flash IDE CS4.

See the source by clicking here.