【问题标题】:as3 change font size as stage size changesas3 随着舞台大小的变化改变字体大小
【发布时间】:2015-08-03 11:46:03
【问题描述】:

在阅读时,我想随着舞台大小的变化而改变字体大小。

我有私有 var myFormat:TextFormat = new TextFormat();

然后当对象被制作出来时,它会写下以下内容

        _buttonText.wordWrap = true;

        myFormat.size = 15;
        myFormat.align = TextFormatAlign.CENTER;
        _buttonText.textColor = 0x222428;
        myFormat.bold = 'true';
        _buttonText.defaultTextFormat = myFormat;       
        _buttonText.text = text;

然后在我的输入框架中,我想调整文本的大小,我尝试了几件事,但似乎没有任何效果,目前看起来像这样。

      myFormat.size = stage.stageWidth / 136.53;

感谢您的帮助

【问题讨论】:

    标签: actionscript-3 flash


    【解决方案1】:

    除非应用于 TextField,否则 TextFormat 对象无效。此外,如果字体大小应该与舞台大小相关联,那么还应该应用某种因子大小。最后看起来是这样的:

    myFormat.size = 15 * fontSizeFactor;
    //_buttonText.defaultTextFormat = myFormat;this is irrelevant if size should be dynamic.
    //instead text should be set then TextFormat should be set again.
    _buttonText.text = text;   
    _buttonText.setTextFormat(myFormat);//this is dynamic
    

    现在进入框架:

    myFormat.size = 15 * fontSizeFactor;
    _buttonText.setTextFormat(myFormat);//apply the format again or else nothing will happen
    

    【讨论】:

    • 感谢您的帮助,现在当文本所在的按钮移动文本时,文本不会停留在按钮内,您知道如何解决该问题吗?我试过 sp.removechild sp.addchild 但它从来没有解决问题
    • TextField 根据字体大小增大或缩小,甚至可以根据 TextFieldAutoSize 属性移动。您必须根据其变化的大小通过代码重置其位置。
    • 我已经写了 _buttonText.autoSize = TextFieldAutoSize.CENTER;但是,如果按钮向左移动并变小,则文本最终会出现在按钮之外。至少字体大小现在正在改变
    猜你喜欢
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 2019-12-12
    • 2014-03-23
    • 2018-01-02
    • 1970-01-01
    相关资源
    最近更新 更多