如何在AS3中防止此任意文本截断

时间:2011-12-28 17:42:27

标签: arrays actionscript-3 textfield

下面是填充菜单的代码。除了一个关键部分外,一切似乎都很好用,没有任何错误。我的megaPages数组的值为["HOME","BABIES","BRIDALS","MISC","WEDDINGS","ABOUT"],但屏幕上显示的实际文本(由megaPages生成)如下所示:

strange menu problems

正如您所看到的,某些文本被任意截断。我已经跟踪了文本字符串,因为它们在菜单构建的各个阶段通过各种函数,并且它们总是正确的,但不知何故,当每个DisplayObject在屏幕上显示时,字母被省略(注意'HOME' abd'关于'很好)。我甚至不知道从哪里开始这个问题。

    function buildMenu() {
        var itemMCs = new Array();

        for (var i = 0; i < megaPages.length; i++) {
            megaPages[i] = megaPages[i].toUpperCase();
            trace(megaPages[i]); // at each iteration, traces as follows "HOME","BABIES","BRIDALS","MISC","WEDDINGS","ABOUT"
            var textMC = createText(megaPages[i]);

            var itemMC = new MovieClip();
            if (i!=0) {
                var newLink = new PlateLink();
                newLink.y = 0;
                itemMC.addChild(newLink);
            }


            var newPlate = new Plate();
            if (i==0) {
                newPlate.y = 0;
            } else {
                newPlate.y = newLink.height - 2;
            }
            newPlate.x = 0;
            newPlate.width = textMC.width + (plateMargin*2);
            itemMC.addChild(newPlate);

            if (i!=0) {
                newLink.x = (newPlate.width/2) - (newLink.width/2);
            }

            textMC.x = plateMargin;
            textMC.y = newPlate.y + .5;
            itemMC.addChild(textMC);

            itemMCs.push(itemMC);

            itemMC.x = (homeplateref.x + (homeplateref.width/2)) - (itemMC.width/2);
            if (i==0) {
                itemMC.y = homeplateref.y;
            } else {
                itemMC.y = itemMCs[i-1].y + (itemMCs[i-1].height - 6);
            }
            menuRef.addChild(itemMC);

        }

    }

    function createText(menuTitle) {

        trace(menuTitle);

        var textContainer : MovieClip = new MovieClip();

        var myFont = new Font1();

        var backText = instantText(menuTitle, 0x000000);

        backText.x = 1;
        backText.y = 1;

        var frontText = instantText(menuTitle, 0xFFFFFF);

        frontText.x = 0;
        frontText.y = 0;

        textContainer.addChild(backText);
        textContainer.addChild(frontText);
        return textContainer;
    }

    function instantText(textContent, color) {

        trace(textContent); // again, traces the right text each time it is fired

        var myFont = new Font1();
        var myFormat:TextFormat = new TextFormat();
        myFormat.size = 18;
        myFormat.align = TextFormatAlign.CENTER;
        myFormat.font = myFont.fontName;

        var myText:TextField = new TextField();
        myText.defaultTextFormat = myFormat;
        myText.embedFonts = true;
        myText.antiAliasType = AntiAliasType.ADVANCED;
        myText.text = textContent;
        myText.textColor = color;
        myText.autoSize = TextFieldAutoSize.LEFT;           
        trace(myText.text);

        return myText;
    }

1 个答案:

答案 0 :(得分:2)

您需要为正在使用的字体嵌入所有必需的字符。

对于在Flash中创建的文本字段:
选择TextField,然后点击属性面板中的“嵌入”按钮。

对于动态创建的文本字段:
当您将字体设置为导出(Font1时),请确保包含所需的所有字符。

您可以选择嵌入所有大写字符,或只输入这些特定菜单项所需的字符。