ChrisInch.com

Innovation, practicality and creativity

Flash addXMLPath example

Posted by Chris Inch on Aug. 1st, 2007

I was recently working on an application in Flash which required the use of Flash's Locale class. It didn't take long before I was consulting the documentation for some of the methods and I ran across the addXMLPath method. Adobe (Macromedia at the time) was nice enough to include an example of how to use Locale.addXMLPath, however the example provided doesn't even use addXMLPath()! The example provides no extra help whatsoever. I've created this small article to give an example on how to use Locale.addXMLPath().

Actually, using addXMLPath is pretty straight forward. It's main purpose is to load XML language files from a custom location instead of the default set up by Flash. If you've ever created an XLIFF file using Flash's Strings panel, then you should know that Flash creates an XML file for each language, but it puts it in your working directory, under a subdirectory and named using your FLA's filename. Example:

workingDir/en/MyFlashFile_en.xml

If you have Flash file that needs to open an XLIFF file from another directory, you will need to use addXMLPath() to tell Flash where to find that file. Simply put, addXMLPath sets the path to XML files holding the translations for the specified language. An example:

Locale.addXMLPath("en", "../locale/locale_en.xml");

The above example tells the Locale class that English ("en") translations are found in the file "../locale/locale_en.xml". Note that you can specify a separate path for each language and this path can be relative to the working directory. This is handy when, like me, you are turned off by the fact that Flash makes a new directory for each language's XML file. I personally would like to see all the languages in one directory. If I put all my language XML files in a folder called "locale" then this is how I would use addXMLPath:

Locale.addXMLPath("en", "locale/locale_en.xml");
Locale.addXMLPath("fr", "locale/locale_fr.xml");
Locale.addXMLPath("ko", "locale/locale_ko.xml");
Locale.setLoadCallback(Delegate.create(this, languageLoaded));
Locale.loadLanguageXML("en");

private function languageLoaded(success:Boolean):Void {
    trace(Locale.loadString("IDS_HELLO");
}

And there you have it... A (detailed) example of how to use addXMLPath.

Comments

Comments are temporarily disabled. Please contact me if you have any questions/comments.

Chris Inch is a programmer, web developer, musician, graphic designer, photographer and handyman from Ottawa, Ontario, Canada. Chris graduated from the University of Waterloo in 2004 with a degree in Computer Science. He currently works professionally as an ActionScript 3.0 developer.

Links

Recent Blog Post

DIY Super Clamp
Posted by Chris Inch on Nov. 9th, 2008

Tags

Misc, SEO, Flash, ActionScript, OpenID, Life, Games, HTML, Money, Tips, CSS, Sites, Python, Django, Shaving, Handyman, Design, Wushu, Complaints, Regex, Moleskine, DIY

RSS Feeds