【问题标题】:Text Input Rotation + Styling the text文本输入旋转 + 设置文本样式
【发布时间】:2014-09-18 15:06:04
【问题描述】:

我在舞台上有textInput,它不是组件;而是一个textField,它被设置为inputText。我在舞台上还有一个按钮,可以将inputField 中选定的文本部分加粗。

这是代码,运行良好:

var formatDefBold: TextFormat = new TextFormat();
formatDefBold.bold = false;
var formatBold: TextFormat = new TextFormat();
formatBold.bold = true;

boldBtn.addEventListener(MouseEvent.CLICK, makeBold);

function makeBold(event: MouseEvent):void
{
    var sbi:Number = myInputField.selectionBeginIndex;
    var sei:Number = myInputField.selectionEndIndex;

    if (sbi != sei)
    {
        var section:TextFormat = myInputField.getTextFormat(sbi,sei);

        if (section.bold == false)
        {
            myInputField.setTextFormat(formatBold, sbi, sei);
        }
        else
        {
            myInputField.setTextFormat(formatDefBold, sbi, sei);
        }
        stage.focus = this[selectedTextField]; // highlight the selected text again.
    }
}

问题: 当我旋转 textInput 时,文本消失了。如果我嵌入字体并选择另一种抗锯齿方法,如“动画抗锯齿”,旋转后的 textInput 可以很好地显示文本,但 makeBold 函数不起作用。 我试过不同的字体。 Sans,Arial,我嵌入了它的所有样式(粗体、斜体、粗体斜体)。什么都没有!

我尝试将textInput 放在movieClip 中,然后旋转movieClip。不工作。

我也尝试过为textInput 设置embedFonts 参数,不确定是否正确

myInputField.embedFonts = true;

这一次即使textField 没有旋转,文本也会消失。

我真的被卡住了,想不出任何其他方法来使粗体功能与旋转的textInput 一起使用。

【问题讨论】:

    标签: actionscript-3 rotation textinput


    【解决方案1】:

    嵌入方法

    对于文本字段的旋转等任何操作,您应该首先嵌入文本字体。

    myText.text = "rotation with embed font";
    myText.rotation = 10;
    

    您的文本字段“myText”实际放置在场景中。当您单击它时,在“属性”窗口中,执行以下操作:

    • anti-alias(动画抗锯齿)
    • 字体嵌入

    要嵌入字体,请单击“嵌入”按钮 > 窗口“字体嵌入”>“字符范围”> 选择:“大写”、“小写”、“数字”、“标点”。 (不要点击“全部”)

    3D 方法

    您还可以使用 Flash Player 10 中提供的 3D 方法在不嵌入字体的情况下旋转动态文本字段。

    var myTextField:TextField = new TextField();
    this.addChild(myTextField);
    
    var fo:TextFormat = new TextFormat("Arial", 11, 0xFF0000);
    
    myTextField.defaultTextFormat = fo;
    myTextField.text = "3D rotation";
    myTextField.rotationZ = 45;
    

    你的情况...

    在您的情况下,以下代码可以完美运行(您只需在场景中放置一个名为“boldBtn”的按钮):

    var myInputField:TextField = new TextField();
    this.addChild(myInputField);
    
    var fo:TextFormat = new TextFormat("Verdana", 12, 0x000000, false);
    
    myInputField.defaultTextFormat = fo;
    myInputField.text = "3D rotation";
    myInputField.rotationZ = 45;
    
    boldBtn.addEventListener(MouseEvent.CLICK, makeBold);
    
    function makeBold(event:MouseEvent):void
    {
        fo.bold = !fo.bold;
        myInputField.setTextFormat(fo);
    }
    

    【讨论】:

    • 第二种方法是通过actionscript工作。但是第一个在舞台上有 myTextFiled 的,不起作用。每当我为动画启用抗锯齿功能时,我都尝试按照您所说的方式嵌入字体(不是全选...),粗体功能停止工作;即使我不旋转 textField
    • 我将抗锯齿设置为默认值“使用设备字体”,并使用 rotationZ 旋转文本字段。它奏效了!使用默认抗锯齿的旋转(不是旋转Z)不会显示文本。并且使用带抗锯齿的旋转(不是旋转Z)会使粗体功能不起作用。
    • @Milad Ghattavi - 很高兴为您提供帮助。您不需要创建两种文本格式。如我的示例所示,您只需更改 textFormat 的“bold”属性,并使用 setTextFormat() 方法将其设置为 textField。
    【解决方案2】:

    我将抗锯齿设置为默认值“使用设备字体”并使用rotationZ 旋转文本字段。它奏效了!

    使用rotation(不是rotationZ)和默认抗锯齿不会显示文本。

    使用rotation(不是rotationZ)和抗锯齿会使粗体功能不起作用。

    所以只需添加这行代码即可解决:

    myInputField.rotationZ = 45;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      相关资源
      最近更新 更多