package FlashChat { import flash.events.Event; import flash.xml.XMLDocument; import flash.xml.XMLNode; import mx.controls.Alert; import mx.utils.ObjectProxy; public class Language extends Object { private static var _xml:XMLDocument; public static var id: String; [Bindable] public static var desktop:ObjectProxy = new ObjectProxy(); [Bindable] public static var dialog:ObjectProxy = new ObjectProxy(); [Bindable] public static var messages:ObjectProxy = new ObjectProxy(); [Bindable] public static var status:ObjectProxy = new ObjectProxy(); [Bindable] public static var usermenu:ObjectProxy = new ObjectProxy(); [Bindable] public static var login: String; public static var defLanguage:Object; public static var tdialog:Object; public static function parse(s:String,d:Object):String { while (s.search("USER_LABEL") > - 1) s = s.replace("USER_LABEL",d.USER_LABEL); while (s.search("ROOM_LABEL") > - 1) s = s.replace("ROOM_LABEL",d.ROOM_LABEL); while (s.search("TIMESTAMP") > - 1) s = s.replace("TIMESTAMP",d.TIMESTAMP); return s; } public static function set xml(s:String):void { tdialog = new Object(); var _xml:XMLDocument = new XMLDocument(); _xml.ignoreWhite = true; _xml.parseXML(new XML(s)); var xmlNode:XMLNode = _xml.firstChild; id = xmlNode.attributes.id; for (var i:uint = 0; i < xmlNode.childNodes.length; i++) { var att:Object = (xmlNode.childNodes[i] as XMLNode).attributes; switch(xmlNode.childNodes[i].nodeName) { case "desktop": desktop = new ObjectProxy(att); break; case "dialog": if (att.id) tdialog[att.id] = att; else tdialog = att; break; case "messages": messages = new ObjectProxy(att); if (xmlNode.childNodes[i].firstChild) { login = xmlNode.childNodes[i].firstChild.firstChild.nodeValue; } break; case "status": status = new ObjectProxy(att); var statusIndex: uint = 1; for (var s: String in att) { var curStatus: Object = {label: att[s], data: statusIndex, key: s}; if ('here' == s && 1 != statusIndex) { var tmp: Object = Settings.statuses[0]; tmp.data = statusIndex; curStatus.data = 1; Settings.statuses[0] = curStatus; curStatus = tmp; } Settings.statuses.push(curStatus); Settings.statuses.push(); statusIndex++; } break; case "usermenu": usermenu = new ObjectProxy(att); break; default: break; } } dialog = new ObjectProxy(tdialog); Settings.dispatchEvent(new Event("updateLanguage")); } } }