文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页网页设计Flash → 在Flash中用XML实现多语言支持

在Flash中用XML实现多语言支持

时间:2004/11/7 2:22:00来源:本站整理作者:蓝点我要评论(0)


            
             
              
             
            

               
               

            



            下载本教程源文件请点击这里。

  一、介绍

  互联网是没有国界的,但互联网是有多语言的,有关多语言支持问题很令人头痛,在制作Flash作品,特别是在制作网页方面应用的过程中,对多种语言的支持就显得越发重要了。本文介绍了一种在Flash中利用XML来实现多语言支持的方法。

  二、实现原理

  可以利用Flash支持unicode编码来实现多语言的支持。先将XML文档的编码设置为utf-8,将要显示的内容保存在XML文档中。在Flash中创建一个XML对象,在此对象中导入相应的XML文档,解释并显示出来,就实现了多语言的支持。注意此种实现方法只能支持utf-8编码的语言。

  三、制作实例

  我们来实现一个支持英语、法语、德语、意大利语、葡萄牙语、西班牙语六种语言的例子,例子的效果如图1所示。当然,要实现更多的语言支持,实现的原理是大同小异的,只是需要简单的更换一下XML文档而已。


  A、准备XML文档

  我们要将所需要显示的内容都保存在XML文档中,其中最重要的是在XML文件头中设置encoding="utf-8"。

  1、新建一个XML文件,命名为english.xml,本文件用来支持英语,注意在用编辑工具编辑的时候,保存的格式要为utf-8格式,保存的内容如下所示:










English
French
Spanish
German
Italian
Portuguese
Here is an example of what you can do with external XML files and Flash MX. Click on any flag and automatically all the text fields are updated to whatever language you select. The movie clip does not translate text. It simply reads the translated text you write in the XML document. Then it is loaded into your movie.


 


2、新建一个XML文件,命名为french.xml,本文件用来支持法语,保存的格式为utf-8格式,保存的内容如下:










Anglais
Fran?ais
Espagnol
Allemand
Italien
Portugais
Voici un exemple de ce que vous pouvez faire avec dossiers XML externes et éclat MX. Cliquez sur tout drapeau et automatiquement tous les champs du texte sont mis à jour à quel que soit langue que vous sélectionnez. La pince du film ne traduit pas texte. Il lit simplement le texte traduit que vous écrivez dans le document XML. Alors il est chargé dans votre film.


  3、新建一个XML文件,命名为german.xml,本文件用来支持德语,保存的格式为utf-8格式,保存的内容如下:










Englisch
Franz?sisch
Spanisch
Deutsch
Italienisch
Portugiesisch
Hier ist ein Beispiel von dem, was Sie mit externen XML-Akten und Flash MX machen k?nnen. Klicken Sie auf jeder Fahne an, und automatisch werden alle Textfelder zu welch Sprache aktualisiert der Sie auserlesen. Die Filmklammer übersetzt keinen Text. Es lautet den übersetzten Text, den Sie das XML-Dokument einfügen, einfach. Dann wird es in Ihren Film beladen.


  4、新建一个XML文件,命名为italian.xml,本文件用来支持意大利语,保存的格式为utf-8格式,保存的内容如下:










Inglese
Francese
Spagnolo

Tedesco
Italiano
Portoghese
Ecco un esempio di quello che Lei può fare con archivi di XML esterni e MX Abbaglianti. Clicchi su alcuna bandiera ed automaticamente tutti i campi di testo sono aggiornati a lingua purchessia che Lei seleziona. Il clip di film non traduce testo. Legge semplicemente il testo tradotto che Lei scrive nel documento di XML. Poi è caricato nel Suo film.



  5、新建一个XML文件,命名为portuguese.xml,本文件用来支持葡萄牙语,保存的格式为utf-8格式,保存的内容如下:











Engels
Frans
Spaans
Duits
Italiaans
Portugees
Aqui é um exemplo do que você pode fazer com arquivos de XML externos e Flash MX. Fa?a tique-taque em qualquer bandeira e automaticamente todos os campos de texto s?o atualizados a qualquer idioma que você seleciona. O clipe de filme n?o traduz texto. Lê o texto traduzido que você escreve no documento de XML simplesmente. Ent?o está carregado em seu filme.

6、新建一个XML文件,命名为spanish.xml,本文件用来支持西班牙语,保存的格式为utf-8格式,保存的内容如下:









Inglés
Francés
Espa?ol
Alemán
Italiano
Portugués
Aquí es un ejemplo de lo que usted puede hacer con los archivos de XML externos y Llamarada MX. Haga clic en cualquier bandera y automáticamente todos los campos del texto se ponen al día a idioma cualquier que usted selecciona. La grapa de la película no traduce el texto. Lee el texto traducido que usted escribe en el documento de XML simplemente. Entonces está cargado en su película.



  B、制作Flash文件

  1、在Flash中新建一个文件,将影片的大小设置为760 px * 200 px,背景设置为黑色。如图2所示。




  2、在场景中用文本工具拉7个文本框,类型都设置为Dynamic_Text,分别命名为english_btn、french_btn、spanish_btn、german_btn、italian_btn、portuguese_btn、content_txt。在场景中的摆放位置如图3所示,注意中间大的那个为content_txt。




  3、在场景的时间轴上面,新建一个层,命名为action,在action层的第一帧上面插入关键帧(插入关键帧的方法为在时间轴中用鼠标右键点击此帧,选取Insert Key frame即可),将帧的标签设置为english,在此帧的Action面板上面添加如下内容:








content = new XML(); //注释1
content.ignoreWhite = true; //注释2
content.load("xml/english.xml"); //注释3
function languageOnLoad() { //注释4
_root.english_btn.text = content.firstChild.childNodes[0].firstChild;
_root.french_btn.text = content.firstChild.childNodes[1].firstChild;
_root.spanish_btn.text = content.firstChild.childNodes[2].firstChild;
_root.german_btn.text = content.firstChild.childNodes[3].firstChild;
_root.italian_btn.text = content.firstChild.childNodes[4].firstChild;
_root.portuguese_btn.text = content.firstChild.childNodes[5].firstChild;
_root.content_txt.text = content.firstChild.childNodes[6].firstChild;
}
content.onLoad = languageOnLoad; //注释5
注释1:创建一个XML对象。
  注释2:忽略XML对象中的空格。
  注释3:导入XML文档,此文档中的内容为要显示的英语内容。
  注释4:设置导入XML文档时的响应函数。在此函数中,分别设置了各个按钮所对应的文本框的显示内容。
  注释5:设置响应函数。

  4、在action层的第八帧上面插入关键帧,将帧的标签设置为french,在此帧的Action面板上面添加如下内容:







content = new XML();
content.ignoreWhite = true;
content.load("xml/french.xml"); //注释1
function languageOnLoad() {
_root.english_btn.text = content.firstChild.childNodes[0].firstChild;
_root.french_btn.text = content.firstChild.childNodes[1].firstChild;
_root.spanish_btn.text = content.firstChild.childNodes[2].firstChild;
_root.german_btn.text = content.firstChild.childNodes[3].firstChild;
_root.italian_btn.text = content.firstChild.childNodes[4].firstChild;
_root.portuguese_btn.text = content.firstChild.childNodes[5].firstChild;
_root.content_txt.text = content.firstChild.childNodes[6].firstChild;
}
content.onLoad = languageOnLoad;
stop();


  注释1:导入XML文档,此文档中的内容为要显示的法语内容。

  5、在action层的第八帧上面插入关键帧,将帧的标签设置为spanish,在此帧的Action面板上面添加如下内容:








content = new XML();
content.ignoreWhite = true;
content.load("xml/spanish.xml"); //注释1
function languageOnLoad() {
_root.english_btn.text = content.firstChild.childNodes[0].firstChild;
_root.french_btn.text = content.firstChild.childNodes[1].firstChild;
_root.spanish_btn.text = content.firstChild.childNodes[2].firstChild;
_root.german_btn.text = content.firstChild.childNodes[3].firstChild;
_root.italian_btn.text = content.firstChild.childNodes[4].firstChild;
_root.portuguese_btn.text = content.firstChild.childNodes[5].firstChild;
_root.content_txt.text = content.firstChild.childNodes[6].firstChild;
}
content.onLoad = languageOnLoad;
stop();


  注释1:导入XML文档,此文档中的内容为要显示的西班牙语内容。

  6、在action层的第八帧上面插入关键帧,将帧的标签设置为german,在此帧的Action面板上面添加如下内容:








content = new XML();
content.ignoreWhite = true;
content.load("xml/german.xml"); //注释1
function languageOnLoad() {
_root.english_btn.text = content.firstChild.childNodes[0].firstChild;
_root.french_btn.text = content.firstChild.childNodes[1].firstChild;
_root.spanish_btn.text = content.firstChild.childNodes[2].firstChild;
_root.german_btn.text = content.firstChild.childNodes[3].firstChild;
_root.italian_btn.text = content.firstChild.childNodes[4].firstChild;
_root.portuguese_btn.text = content.firstChild.childNodes[5].firstChild;
_root.content_txt.text = content.firstChild.childNodes[6].firstChild;
}
content.onLoad = languageOnLoad;
stop();


  注释1:导入XML文档,此文档中的内容为要显示的德语内容。


 7、在action层的第八帧上面插入关键帧,将帧的标签设置为italian,在此帧的Action面板上面添加如下内容:










content = new XML();
content.ignoreWhite = true;
content.load("xml/italian.xml"); //注释1
function languageOnLoad() {
_root.english_btn.text = content.firstChild.childNodes[0].firstChild;
_root.french_btn.text = content.firstChild.childNodes[1].firstChild;
_root.spanish_btn.text = content.firstChild.childNodes[2].firstChild;
_root.german_btn.text = content.firstChild.childNodes[3].firstChild;
_root.italian_btn.text = content.firstChild.childNodes[4].firstChild;
_root.portuguese_btn.text = content.firstChild.childNodes[5].firstChild;
_root.content_txt.text = content.firstChild.childNodes[6].firstChild;
}
content.onLoad = languageOnLoad;
stop();



  注释1:导入XML文档,此文档中的内容为要显示的意大利语内容。

  8、在action层的第八帧上面插入关键帧,将帧的标签设置为portuguese,在此帧的Action面板上面添加如下内容:









content = new XML();
content.ignoreWhite = true;
content.load("xml/portuguese.xml"); //注释1
function languageOnLoad() {
_root.english_btn.text = content.firstChild.childNodes[0].firstChild;
_root.french_btn.text = content.firstChild.childNodes[1].firstChild;
_root.spanish_btn.text = content.firstChild.childNodes[2].firstChild;
_root.german_btn.text = content.firstChild.childNodes[3].firstChild;
_root.italian_btn.text = content.firstChild.childNodes[4].firstChild;
_root.portuguese_btn.text = content.firstChild.childNodes[5].firstChild;
_root.content_txt.text = content.firstChild.childNodes[6].firstChild;
}
content.onLoad = languageOnLoad;
stop();



  注释1:导入XML文档,此文档中的内容为要显示的葡萄牙语内容。

  9、在场景中放置6个按钮,分别表示点击后显示英语、法语、德语、意大利语、葡萄牙语、西班牙语,并在表示英语的按钮的Action面板上面增加如下语句:









on (release) {
gotoAndStop("english");
}



  在表示法语的按钮的Action面板上面增加如下语句:









on (release) {
gotoAndStop("french");
}



 在表示德语的按钮的Action面板上面增加如下语句:









on (release) {
gotoAndStop("german");
}

在表示意大利语的按钮的Action面板上面增加如下语句:







on (release) {
gotoAndStop("italian");
}


  在表示葡萄牙语的按钮的Action面板上面增加如下语句:








on (release) {
gotoAndStop("portuguese");
}


  在表示西班牙语的按钮的Action面板上面增加如下语句:








on (release) {
gotoAndStop("spanish");
}


  此时场景中的情况应该如图4所示。




  C、小结

  至此,实例就制作完成了,将XML文档都放置在一个名为xml的文件夹中,在Flash中生成实例的swf文件,将生成的swf文件放置在跟xml文件夹同级的目录中,打开swf文件就可以看到实例效果。注意在Flash中是看不到效果的,因为在Flash导入不了xml文档。
如果想要支持更多的语言,只需要更换XML文档的内容就可以实现,所以应用还算是比较简单的。

  下载本教程源文件请点击这里。

相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 Flash CS4基础入门 如何在Flash中打开一个定制的浏览器新窗口?学习ActionScript 3.0的6个好处几个小技巧精简Flash文件体积在Flash动画中添加“加为收藏”和“设为首页

人气排行 Flash游戏制作--小熊拼图用Flash实现几种镜头效果Flash制作动画知识:遮罩Flash如何做鼠标指针样式Flash制作环形文字Flash制作声情并茂的电子相册实例讲解flashMTV制作全过程(3)鼠标效果系列教程:游动的鱼