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

#1 Emurnunforp commented on Oct. 8th, 2009 at 12:25 a.m.:

Hi People
How are you doing?

#2 VakeGymnbaimbisk commented on Nov. 24th, 2009 at 4:06 a.m.:

...please where can I buy a unicorn?

#3 TSwain commented on Feb. 7th, 2010 at 4:20 a.m.:

There's good info here. I did a search on the topic and found most people will agree with your blog. Keep up the good work mate!

#4 yurgelis commented on Feb. 11th, 2010 at 9:27 a.m.:

hola esperon que me ayuden, estoy tratando de abrir un juego que se llama farm ville y me aparece una leyenda que dice que el archivo flashLocaleXml.xml_4.gz esta daƱado, quisiera saber si eso es el juego o es mi pc? gracias, saludos y espero su respuesta

#5 acid commented on April 14th, 2010 at 6:26 p.m.:

and you couldn't be a little forgiving, in the dictionary they said 'thank you chris' and here you've bashed them in the intro. you're da man chris.

#6 NBA player shoes commented on April 17th, 2010 at 1:12 a.m.:

very well information you write it very

clean. I'm very lucky to get this information from you.

#7 China Mbt Shoes commented on May 3rd, 2010 at 12:40 p.m.:

i am happy to find it thanks for sharing it here. Nice work.

#8 hermes birkin handbags commented on May 5th, 2010 at 1:57 a.m.:

nice to be here.... thanks for share

#9 free trial commented on May 7th, 2010 at 3:15 p.m.:

Great journey and experience!

#10 Hermes birkin bag commented on May 9th, 2010 at 9:15 p.m.:

Great article, i

hope can know much information About it!

#11 make money on the web commented on Aug. 12th, 2010 at 9:13 p.m.:

very well

information you write it very clean. I'm very lucky to get this information from you.

Post a comment

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

Commercial Photography Blog
Posted by Chris Inch on Aug. 25th, 2010

Tags

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

RSS Feeds