Locale.loadLanguageXML()无法在外部脚本中使用

时间:2013-06-28 20:24:08

标签: actionscript-3 locale multilingual flash-cs6

我在添加到时间轴的第一帧时有一个多语言使用的脚本。但是,当我尝试使其适应外部.as脚本时,它会引发TypeError,我无法弄清楚原因。

以下是时间轴中的代码:

import fl.data.DataProvider;
import fl.text.TLFTextField;
import flash.text.Font;
import flashx.textLayout.elements.*;
import flashx.textLayout.formats.*;

//------------------
// CREATE TLFTEXTFIELD:

var field_001:TLFTextField = new TLFTextField();
field_001.x = 20;
field_001.y = 50;
field_001.width = 342
field_001.height = 54;
field_001.background = true;
addChild(field_001); 

// Create text format
var format:TextLayoutFormat = new TextLayoutFormat();
format.fontFamily = "Arial";
format.fontSize = 36;
format.color = 0x666666;

// Apply the format
var textFlow:TextFlow = field_001.textFlow;
textFlow.hostFormat = format;

//------------------
// SETUP LOCALE OBJECT:

var languages:Object = new Object();    // Stores flags for loaded languages
var localeDefault:String = "ar";        // Default language
var locale:String = "ar";              // Current language selected in combobox

// Event handler for Locale object
function localeLoadedHandler(success:Boolean):void 
{
    if( success )
{
        // Mark language as loaded and show localized string
        languages[locale] = true;
        field_001.text = Locale.loadStringEx("IDS_FIRSTFIELD", locale);
                // field_002 is a field already on stage
        field_002.text = Locale.loadStringEx("IDS_SECONDFIELD", locale);
    }
}    
// Load the default language...
Locale.setDefaultLang(localeDefault);
Locale.setLoadCallback(localeLoadedHandler);
trace("Locale.getDefaultLang() is: " + Locale.getDefaultLang());
Locale.loadLanguageXML(Locale.getDefaultLang());

这是我对外部脚本的改编,并设置为一个名为“tempchild.swf”的独立swf的类,我想稍后在父swf中打开:

package com.marsinc {

import fl.text.TLFTextField;
import flash.text.Font;
import flashx.textLayout.elements.*;
import flashx.textLayout.formats.*;
import flash.display.MovieClip;
import fl.lang.Locale;

public class tempchild extends MovieClip {

    //------------------
    // SETUP LOCALE OBJECT:

    private var languages:Object;           // Stores flags for loaded languages
    private var localeDefault:String;       // Default language
    private var locale:String;          // Current language selected in combobox
    private var field_001:TLFTextField;
    private var format:TextLayoutFormat;

    public function tempchild() 
    {
        // constructor code
        languages = new Object();
        localeDefault = "es";   
        locale = "es";

        //------------------
        // CREATE TLFTEXTFIELD:

        field_001 = new TLFTextField();
        field_001.x = 20;
        field_001.y = 50;
        field_001.width = 342
        field_001.height = 54;
        field_001.background = true;
        addChild(field_001); 

        // Create text format
        format = new TextLayoutFormat();
        format.fontFamily = "Arial";
        format.fontSize = 36;
        format.color = 0x666666;

        // Apply the format
        var textFlow:TextFlow = field_001.textFlow;
        textFlow.hostFormat = format;

        // Load the default language...
        Locale.setDefaultLang(localeDefault);
        Locale.setLoadCallback(localeLoadedHandler);
        trace("Locale.getDefaultLang() is: " + Locale.getDefaultLang()); // displays "es"
        Locale.loadLanguageXML(Locale.getDefaultLang()); // this line returns an error
    }


    // Event handler for Locale object
    private function localeLoadedHandler(success:Boolean):void 
    {

        trace("running the loaded handler");
        if( success )
        {
            // Mark language as loaded and show localized string
            languages[locale] = true;
            field_001.text = Locale.loadStringEx("IDS_FIRSTFIELD", locale);
            //field_002.text = Locale.loadStringEx("IDS_SECONDFIELD", locale);
        }
    }    


}

这是输出窗口中的错误:

TypeError:错误#1010:术语未定义且没有属性。

在fl.lang :: Locale $ / loadXML()

at fl.lang :: Locale $ / loadLanguageXML()

在com.marsinc :: tempchild()

现在正在四处寻找答案,我被困住了。任何帮助是极大的赞赏。谢谢!

- 凯文

1 个答案:

答案 0 :(得分:0)

你可以用(至少)两种方式之一制作.as文件

1)将所有内容完全复制粘贴到.as文件中并执行:

include "[path]filename.as"

2)将代码更改为类
- 将field_001,format,textFlow,languages,localeDefault,locale设为public vars
- 将所有代码插入名为“init”的函数中 - 将“localeLoadedHandler”添加为函数
- 单击您的舞台并将舞台类的属性面板更改为新类

祝你好运!!