Tracing every child nodes
To use Korean font, we needed to find and transform all the textfields in the movieclip.
The transforming function is like this:
public static function transform(textField:TextField, force:Boolean = false):void {
var obj:Object = (CitrusEngine.getInstance().state.getObjectByName("Nanum"));
var mc:MovieClip = (CitrusEngine.getInstance().state.view as AnimatedSpriteView).asMovieClip(obj);
var kls:Class = mc.loaderInfo.applicationDomain.getDefinition("Nanum") as Class;
if((textField.embedFonts == true) && (force == true || I18n.l.substr(0, 2) == Locales.ko.Name)) {
//var font:FontNanum = new FontNanum();
tm = textField.defaultTextFormat;
textField.embedFonts = false;
tm.size = (textField.defaultTextFormat.size as Number) * 0.9;
textField.defaultTextFormat = tm;
textField.setTextFormat(tm);
This code load the font from the CitrusEngine, and transforms the textfield's font when the user's locale is Korean.
My first approach to get all the textfields' list is like this:
static public function recTransform(dOC:DisplayObjectContainer):void
var except:Array = ["TxtAssetCoin", "TxtAssetAcorn", "TxtUnlockCost", "TxtRewardCoin",
"TxtRewardExp", "TxtRipeTime", "TxtCoin", "TxtAcorn", "TxtEnergy", "TxtLevel",
"TxtSponsorCool", "TxtFertilizerCount", "TxtFriendLevel", "TxtFriendCool"];
var n:Number = dOC.numChildren;
for(var i:Number = 0; i < n; i++) {
var child:DisplayObject = dOC.getChildAt(i);
if(child is TextField && except.indexOf(child.name)==-1) {
I18n.transform(child as TextField);
TextField(child).text = I18n.t(TextField(child).text);
if(TextField(child).type != TextFieldType.INPUT)
TextField(child).mouseEnabled = false;
if(child is DisplayObjectContainer)
recTransform(child as DisplayObjectContainer);
So it would just recursively find all the textfields.
But we have been missing some textfields. SimpleButtons has some states, and their children must be explored individually!
static public function recTransform(dOC:DisplayObjectContainer):void
var except:Array = ["TxtAssetCoin", "TxtAssetAcorn", "TxtUnlockCost", "TxtRewardCoin",
"TxtRewardExp", "TxtRipeTime", "TxtCoin", "TxtAcorn", "TxtEnergy", "TxtLevel",
"TxtSponsorCool", "TxtFertilizerCount", "TxtFriendLevel", "TxtFriendCool"];
var n:Number = dOC.numChildren;
for(var i:Number = 0; i < n; i++) {
var child:DisplayObject = dOC.getChildAt(i);
if(child is TextField && except.indexOf(child.name)==-1) {
I18n.transform(child as TextField);
TextField(child).text = I18n.t(TextField(child).text);
if(TextField(child).type != TextFieldType.INPUT)
TextField(child).mouseEnabled = false;
if(child is SimpleButton) {
if(SimpleButton(child).downState is DisplayObjectContainer)
recTransform(SimpleButton(child).downState as DisplayObjectContainer);
if(SimpleButton(child).overState is DisplayObjectContainer)
recTransform(SimpleButton(child).overState as DisplayObjectContainer);
if(SimpleButton(child).upState is DisplayObjectContainer)
recTransform(SimpleButton(child).upState as DisplayObjectContainer);
if(child is DisplayObjectContainer)
recTransform(child as DisplayObjectContainer);