Flash MX 2004 MP3 Player Pg.5

source: http://www.thegoldenmean.com/

5 — XPath

The External XPath Classes

If you have downloaded and looked into the project files, you will have noticed a folder named “com”. You may recall having seen this folder on page two (development structure). On subsequent pages of this tutorial I will discuss how this movie makes use of XPath, but this page will briefly consider what XPath is all about.

Introducing a Power Tool: XPath

The Player’s playlist has been stored in an XML document since the first tutorial in this series. XML is an absolutely fundamental computer technology for data-exchange, and is certainly not limited to internet applications. However, getting at and extracting data from an XML document’s tree structure can be a time consuming exercise in frustration, even for a document as simple as our playlist. If XML is so fundamental, so powerful, so useful, so ubiquitious you’d think someone whould have come up with a way to make it easier to use. You would have thought correctly. XPath is actually a language, and furthermore is a w3.org standard. For those interested, much MUCH more can be read at w3.org’s XPath specifications page.

To summarize (quoting from www.w3.org/TR/xpath):

“XPath is a language for addressing parts of an XML document…
XPath gets its name from its use of a path notation as in URLs for navigating through the heirarchial structure of an XML document…
XPath is also designed so that it has a natural subset that can be used for matching (testing whether or not a node matches a pattern)…

XPath Primer

Subsequent pages in this tutorial will put XPath to practical use in extracting information from an XML file, but I am not going to attempt to go into any depth about the many things XPath is capable of. You are encouraged to learn at least the basics by reading the extremely helpful w3schools XPath tutorial.

Does it work with Flash?

Luckily for us, an industrious person named Neeld Tanksley undertook the task of writing ActionScript 1.0 and 2.0 Classes to bring at least most of XPath’s functionality to Flash coders. He has generously made this code available at his site, xfactorstudio.com. I encourage you to visit, look at some of the other work he has available, and download the latest version of XPath for ActionScript 2.0.

This has indeed been a very superficial discussion of XPath, but I felt it merited a page by iself so the concepts didn’t just get dropped in your lap with no background at all. If you plan future Flash projects using XML, Tanksley’s classes can literally save you hours of work. I encourage you to explore the possibilites on your own.

One final reminder before we move on. Recall that you must have the Package of XPath Classes in your development folder so they can be compiled into your Flash movie, but the XFactorStudio files do not need to be placed on the server once the final .swf has been compiled.

Page Six discusses how to import the XPath classes into your new movie. It is also the page in which the ActionScript begins in earnest by defining key variables.

go to page: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14
divider ornament