Flash with XML multi-language interface

Source: Internet
Author: User
Tags copy interface pack version
Xml

Recently a little bit of space, and began to study flash. Flash to do the application of a lot of people, but the multilingual interface to do very few people, just look at it, found incredibly simple. Turned over the manual. Pounded out, do not dare to enjoy alone, but also please more guidance.

I'm going to make sure of the process.
1. First determine the language version of the operating system->2. Read the associated language pack->3. Replace the display string

First, judge the system language
Judge language has a built-in function System.capabilities.language, this relatively simple, but you can not have every language, so to build an existing language pack array, compare, if not, choose the default language pack.
This is the function of this function

Code Copy Box
function getLANG() {
//已经拥有的语言列表
var LANG_list = ["zh-CN", "en"];
//先用系统函数取语言代码
var LANG = System.capabilities.language;
//是否已经拥有相关语言包,若无,就用英文
for (var i = 0, find = false; i
if (LANG == LANG_list[i]) {
find = true;
break;
}
}
LANG = find ? LANG : en;
return (LANG);
}

Second, read the language pack, and replace
Here I'm using an XML file so I don't have to load all the language packs at once. The language pack structure is as follows, note is UTF-8 code, note here the skill is the filename is the language name, for example Chinese must be zh-cn.xml, English must be en.xml.

Code Copy Box
<?xml version="1.0" encoding="UTF-8"?>
<LANG>
<LANG_username value = "用户名" />
<LANG_password value = "密 码" />
<LANG_login value = "登 陆" />
<LANG_reg value = "注 册" />
<LANG_change value = "en" />
</LANG>

XML file, but also very easy to modify the characteristics of the 2000 FLASH5 features, I now only look carefully. Sweat. We should note that the Flashxml function is not very complete, can not find the value through the node name, only through the index bit to find the value, causing some trouble, although you can write their own functions to recursion, but the efficiency is poor, so think of a unique way to solve.
This is the function of this function

Code Copy Box
function loadLANG(arg) {
//建立XML对象
var LANG_XML = new XML();
LANG_XML.ignoreWhite = true;
//读入XML文件,LANG_path 是自己定义的语言包路径,方便修改
LANG_XML.load(LANG_path+arg+".xml");
//载入后操作以下功能
LANG_XML.onLoad = function(bool) {
//取得XML第一个节点的子节点集数组
var temp = LANG_XML.firstChild.childNodes;
//把值一个一个赋给语言变量
for (var i = 0, find = false; i
_root[temp[i].nodeName] = temp[i].attributes.value;
}
//一次性替换所有显示字符
text_username.text = LANG_username;
text_password.text = LANG_password;
Button_login.label = LANG_login;
Button_reg.label = LANG_reg;
};
}

Finally, the implementation of the second function, you can update the interface at any time.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.