as3 - 如何更改字体,大小和颜色?

时间:2016-03-17 12:58:08

标签: actionscript-3 flash fonts colors size

只是一个警告,我不是很精通编程。如果我正在阅读代码,我或多或少能理解一条线路的成就,但每当我需要从头开始制作东西时,我都会感到挣扎。

我找到了一个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;
        }
    }
}

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

2 个答案:

答案 0 :(得分:0)

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

只需将其应用于TextField实例。

答案 1 :(得分:0)

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

rb.setStyle("textFormat", answerFormat);