【问题标题】:as3 - How to change font, size, and color?as3 - 如何更改字体、大小和颜色?
【发布时间】:2016-07-03 20:13:54
【问题描述】:

只是一个警告,我不是很精通编程。如果我正在阅读代码,我或多或少可以理解一行代码的效果,但每当我需要从头开始制作东西时,我都会很挣扎。

我找到了一个通过脚本处理所有内容的 Flash 测验模板。在对测验进行调整时,我添加了一个背景图像,使文本难以阅读。我想更改使用的文本颜色、大小和字体,但现有代码中没有任何东西可以调整设置,我被卡住了。

.fla 使用两个脚本:一个处理测验的导航和评分,而另一个似乎专门用于格式化问题和答案的显示方式。看起来任何字体调整都会在第二个中进行,所以这是它的完整脚本:

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.events.Event;
    import fl.controls.RadioButton;
    import fl.controls.RadioButtonGroup;

    public class QuizQuestion extends Sprite {
        private var question:String;
        private var questionField:TextField;
        private var choices:Array;
        private var theCorrectAnswer:int;
        private var theUserAnswer:int;
        //variables for positioning:
        private var questionX:int = 25;
        private var questionY:int = 25;
        private var answerX:int = 60;
        private var answerY:int = 55;
        private var spacing:int = 25;

        public function QuizQuestion(theQuestion:String, theAnswer:int, ...answers) {
            //store the supplied arguments in the private variables:

            question = theQuestion;
            theCorrectAnswer = theAnswer;
            choices = answers;
            //create and position the textfield (question):
            questionField = new TextField();
    questionField.text = question;
    questionField.autoSize = TextFieldAutoSize.LEFT;
            questionField.x = questionX;
            questionField.y = questionY;

            addChild(questionField);
            //create and position the radio buttons (answers):
            var myGroup:RadioButtonGroup = new RadioButtonGroup("group1");
            myGroup.addEventListener(Event.CHANGE, changeHandler);
            for(var i:int = 0; i < choices.length; i++) {
                var rb:RadioButton = new RadioButton();
                rb.textField.autoSize = TextFieldAutoSize.LEFT;
                rb.label = choices[i];
                rb.group = myGroup;
                rb.value = i + 1;
                rb.x = answerX;
                rb.y = answerY + (i * spacing);
                addChild(rb);
            }
        }

        private function changeHandler(event:Event) {
            theUserAnswer = event.target.selectedData;
        }
        public function get correctAnswer():int {
            return theCorrectAnswer;
        }
        public function get userAnswer():int {
            return theUserAnswer;
        }
    }
}

我在这里查看了几个问题,并尝试根据我的脚本调整解决方案,但似乎没有改变文本。我得到的最好结果将运行测验没有错误,但似乎也没有对文本进行任何调整。有人可以帮我看看吗?

【问题讨论】:

    标签: actionscript-3 flash fonts colors size


    【解决方案1】:

    要添加到@dimpiax 的答案,您可以像这样设置 RadioButton 标签的样式:

    rb.setStyle("textFormat", answerFormat);
    

    【讨论】:

      【解决方案2】:

      您需要使用 TextFormat。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextFormat.html

      只需将其应用于 TextField 实例即可。

      【讨论】:

      • 我能够更改问题文本,但数组中的答案没有更新。有没有办法改变答案呢? questionFormat = new TextFormat(); questionFormat.size = 12; questionFormat.bold = true; questionFormat.font = "Arial" questionFormat.color = 0xFFFFFF; questionField = new TextField(); questionField.defaultTextFormat = questionFormat; questionField.text = 问题; questionField.autoSize = TextFieldAutoSize.LEFT;问题字段.x = 问题X;问题字段.y = 问题Y;抱歉,我似乎无法添加任何换行符。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多