Skip to main content
Participant
March 16, 2016
Question

Change array text format

  • March 16, 2016
  • 1 reply
  • 666 views

I'm making edits to a quiz that loads questions using an array. One of the edits involves adding a dark background that makes the questions difficult to read. I searched for ways to change text font, size, and color, but none of the tutorials worked. I'm guessing it's because none of the them demonstrated how to do it in an array. Here's what I've got so far:

public class QuizApp extends Sprite
{

  private var quizQuestions:Array;
  private var currentQuestion:QuizQuestion;
  private var currentIndex:int = 0;

  private var prevButton:Button;
  private var nextButton:Button;
  private var finishButton:Button;
  private var closeButton:Button;

  private var score:int = 0;
  private var status:TextField;
  
  public function QuizApp():void
  {
    quizQuestions = new Array();
    createQuestions();
    createButtons();
    createStatusBox();
    addAllQuestions();
    hideAllQuestions();
    firstQuestion();

    var QuizBGInstance:QuizBG = new QuizBG();
    addChildAt(QuizBGInstance, 0);
  }
 
  private function createQuestions()
  {

    quizQuestions.push(new QuizQuestion("Question",
                                                            2,
                                                            "Answer A",
                                                            "Answer B",
                                                            "Answer C"));

    }

How would I go about changing the font, size, and color of the text?

This topic has been closed for replies.

1 reply

robdillon
Participating Frequently
March 16, 2016

Formatting the text should be in the code that displays the text on the stage. My guess is that it's going to be in the function createQuestions() or, maybe, firstQuestion(). There are, probably, one or more TextFormat objects that are written to define the text that will be displayed. Your file's Library will, probably, have one or more fonts embedded. If you want to use different fonts, you'll have to embed those new fonts and give them Actionscript links.

subsea2Author
Participant
March 16, 2016

Okay, I found the firstQuestion function and tried changing the color there. That part of the script looks like this:

private function firstQuestion()

{

     currentQuestion = quizQuestions[0];

     currentQuestion.visible = true;

     currentQuestion.y = 100;

     currentQuestion.x = 100;

     currentQuestion.color = 0xffffff;

}

But when I run it, I get this error: "1119: Access of possibly undefined property color through a reference with static type QuizQuestion."

I've tried adding similar .color lines in the other functions, but I keep getting more or less the same error.

subsea2Author
Participant
March 16, 2016

I noticed that the script references a separate script that appears to handle some of the formatting of text. I'm not sure if this is where any font adjustments should go here or not.

    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;

        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) {

             question = theQuestion;

            theCorrectAnswer = theAnswer;

            choices = answers;

            questionField = new TextField();

            questionField.text = question;

  

           questionField.autoSize = TextFieldAutoSize.LEFT;

            questionField.x = questionX;

            questionField.y = questionY;

  

            addChild(questionField);

            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;

                rb.group = myGroup;

                rb.value = i + 1;

                rb.x = answerX;

                rb.y = answerY + (i * spacing);

                addChild(rb);

            }

        }