David Harris's Technology Blog

ColdFusion, Flex, and other stuff...   (and 341,536 hours, 30 mins in to my plan for global domination)

Search:

Calendar:

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Subscribe:

Enter your email address to subscribe to this blog.

Archives By Subject:

Tags:

action script adobe air ajax cfug coldfusion flash flex frameworks free software fxug general jpgmetadatareader mac off topic opensource papervision spry

Recent Entries:

No recent entries.

Top Posts:

Recent Comments:

Top Commenters:

My Links:

RSS:


A Spry/Javascript gotcha!

I am trying out Spry a bit, and this of course means I need to be brushing up on my JavaScript, and XPath to, as Spry uses XPath on the XML datasets...

I run in to a "this works in FireFox, but not IE" issue that turned out to be my understanding of JavaScript, and not Spry.

Read on for more detail...

I had an example where the XML I was using was something like this:

<images>
<image name="01.jpg" width="267" height="270">
<caption></caption>
<tags>
<tag>Family</tag>
<tag>Fun</tag>
<tag>Fred</tag>
</tags>
</image>
<image name="02.jpg" width="267" height="270">
<caption>My Caption here</caption>
<tags>
<tag>Sun</tag>
</tags>
</image>
</images>

Each Image can have none, one or many "tag" nodes in the "tags" node.

I was attempting to get the tags using XPath like this:

var dsTags = new Spry.Data.XMLDataSet("/gallery/gallery.xml","/images/image[@name='01.jpg']/tags/tag");

As you can see from that, I am getting the tags for the image with the name "01.jpg"

The next step was when the user clicked on the name of any other images in the XML dataset, load the image and then get the tags for that image and display them.

The code in the function that handled the click was something like this:

dsTags.setXPath("/images/image[@name='" + dsImages.getCurrentRow().@name + "']/tags/tag");

The above line of code worked in FF fine, but not in IE. Of course I blamed Spry as any good developer would, and posted a thread on the Spry forums.

...turns out the problem is my Javascript... Can you see my mistake, can ya? huh, huh?

The answer was post by Kinblas of Adobe:

[Quote]

@ is an illegal character in JavaScript:

dsTags.setXPath("/images/image[@name='" + dsImages.getCurrentRow().@name + "']/tags/tag");
Try getting it like this:

dsTags.setXPath("/images/image[@name='" + dsImages.getCurrentRow()[ "@name" ] + "']/tags/tag");
[/Quote]

The difference is refering to the "name" attribute like this:

dsImages.getCurrentRow()[ "@name" ]
...rather than like this...
dsImages.getCurrentRow().@name

Check out the Forum Thread

Thanks Kin for the answer!

Comments