修改Flash的Locale类,以实现多语言自由切换。

类别:编程语言 点击:0 评论:0 推荐:

修改Localt.as的2个函数:
 // call this after all the xml paths have been added
 static function initialize():Void {
  xmlDoc = new XML();
  xmlDoc.ignoreWhite = true;
  xmlDoc.onLoad = function(success:Boolean) {
   onXMLLoad(success); // parse the XML
   callback.call(null, success);
  }
  
  /*var langCode:String = xmlLang;
  if(xmlMap[xmlLang] == undefined) {
   langCode = defaultLang;
  }*/

  var langCode:String = defaultLang;
  if(xmlMap[langCode] == undefined) {
   langCode = xmlLang;
   if (xmlMap[langCode] == undefined)
    return;
  }

  currentXMLMapIndex = 0;
  xmlDoc.load(xmlMap[langCode][0]);
 }

 /******************************************
  * private methods
  ******************************************/
 
 private static function onXMLLoad(success:Boolean) {
  if(success == true) {
   // reset the string map
   delete stringMap;
   stringMap = new Object();
   
   parseStringsXML(xmlDoc);
   assignDelayedInstances();
  }
  else {
   /*var langCode:String = xmlLang;
   if(xmlMap[xmlLang] == undefined) {
    langCode = defaultLang;
   }*/
   var langCode:String = defaultLang;
   if(xmlMap[langCode] == undefined) {
    langCode = xmlLang;
    if (xmlMap[langCode] == undefined)
     return;
   }

   currentXMLMapIndex++;
   var currentXMLMapCount = xmlMap[langCode].length;
   if (currentXMLMapCount != undefined && currentXMLMapCount > currentXMLMapIndex)
    xmlDoc.load(xmlMap[langCode][currentXMLMapIndex]);
  }
 }


调用方式:
mx.lang.Locale.setDefaultLang (”zh-CN”);
mx.lang.Locale.initialize ();

必须条件:
多语言面板设置为自动检测语言设置

本文地址:http://com.8s8s.com/it/it26616.htm