简体   繁体   中英

as3 - How to change font, size, and color?

Just a warning, I'm not very well-versed in programming. I can more or less understand what a line is achieving if I'm reading code, but I struggle whenever I need to make something from scratch.

I found a quiz template for Flash that handles everything through scripts. While making adjustments to the quiz, I added a background image that makes the text difficult to read. I want to change the text color, the size, and font used, but there isn't anything in the existing code to adjust settings and I'm stuck.

There are two scripts that the .fla uses: one handles the navigation and scoring of the quiz, while the other appears to be dedicated to formatting the way the questions and answers appear. It looks like any font adjustments would go in the second one, so here's the full script for it:

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;
        }
    }
}

I've looked at a few questions on here and tried adapting the solutions to my script, but nothing seems to change the text. The best results I get will run the quiz without error, but also don't seem to make any adjustments to the text. Could someone walk me through it?

You need to use TextFormat. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextFormat.html

Just apply it to TextField instance.

要添加到@dimpiax的答案,您可以按如下方式设置RadioButton标签的样式:

rb.setStyle("textFormat", answerFormat);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM