Reply to comment

xfactorstudios xpath4as2

Probably close to the time that Adobe acquired Macromedia Flash- xfactorstudio.com underwent what appears to be a major shift. The site, now devoid of any good usage information or documentation for its XPath4AS2 implementation of XPath for Flash, was redesigned completely, without even the slightest contact link or description of thier product.

In fact, the only thing you can find on the site now is a link to the AS1 and AS2 versions of the class (thankfully). As such, any old links from previously existing articles on the method are now defunct.

I can only assume (and this is strictly an assumption on my part) that Adobe put the squeeze on the xfactor folks, much like they did to the FlashObject crowd following thier new aquisition.

For this reason, and because I use XPath4AS2 all the time, I decided to post the most basic usage of the class here for my own personal reference. I'll gladly take it back down if xfactor ever decides to give us some documentation... (This example also makes use of the Delegate class, a handy way to proxy events and scope to your other functions).

After updating your class path, you'll need to import the class files..

import com.xfactorstudio.xml.xpath.*;
import mx.utils.Delegate;

And now the actual usage, wherein you can employ various and sundry XPath functionality to get what you want from your XML...

var myData:Object = new Object();
var xmlObj:XML = new XML();
	xmlObj.ignoreWhite = true;
var fLoad:Function = function (success:Boolean):Void {
	if (success) {
		myData["someAttributeValue"] = String(XPath.selectNodes(xmlObj, "rootNode/anotherNode@someAttribute"));	
		myData["someNodeValue"] = String(XPath.selectNodes(xmlObj, "rootNode/someNode/text()"));	
		someOtherMethod(); 
	}
};
xmlObj.onLoad = Delegate.create(this, fLoad);
xmlObj.load("path/to/somefile.xml");

function someOtherMethod(){
	trace(myData["someAttributeValue"]); 
	trace(myData["someNodeValue"]); 
}

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.