Tutorial for a Flash Game in ActionScript 3

Create a Flash game in ActionScript 3 by writing statements that implement a simple text-based quiz. Quiz-type games allow ActionScript programmers to create customizable games while learning basic concepts like programming with events and objects. To better understand these concepts, read a primer on object oriented programming languages, of which ActionScript is an example. You can spruce up your quiz's user input form by adding graphics to that form with Flash's "Pencil" or "Paintbrush" tools.

Instructions

    • 1

      Write ActionScript statements that compare the player's response to the quiz questions your program will ask. For example, type the following "if-then" statement block into the "Action" panel. This set of statements compares the text from a user-input control, "txtR," with the correct answer, which is stored in an array of strings called "strA":

      function btnH(event:MouseEvent):void
      {
      if (strA[iQ] == txtR.text ) {
      lblE.text = "That is correct!";

      } else {
      lblE.text = "That is incorrect!";
      }
      iQ = iQ + 1;

      lblQ.text = strQ[iQ];
      }

    • 2

      Write the "AddEventListener" statement that calls your comparison statements when the game's player presses a button on the quiz's form. For example, type this statement above the "if-then" statement you typed in the previous step:

      btnS.addEventListener(MouseEvent.CLICK, btnH);

    • 3

      Write statements that load your quiz's questions and answers into array variables. For example, paste the following statements above the "addEventListener" statement from the previous step. These statements define the array variables "strQ" and "strA," which hold the quiz's questions and correct answers. You can type your own questions and answers in place of those listed here:

      var strQ:Array = ["What is 14 times 3?", "What scientist developed the theory of relativity?", "What famous artist painted the Mona Lisa?" ]
      var strA:Array = ["42", "Einstein", "da Vinci"];
      var iQ:int;
      iQ= 0;
      lblQ.text = strQ[0];

    • 4

      Press "Control" and "Home" in the "Action" window to move to the top of the window, then type the "Import" statements that load the library subroutines your game needs to run. For example, paste the following statements at the top of the "Action" window. These statements provide access to the input-output and other functions your game needs to display quiz questions and answers, and to evaluate player responses:

      import flash.events.Event;
      import fl.controls.RadioButtonGroup;
      import fl.events.ComponentEvent;
      import flash.text.*;
      import fl.events.ColorPickerEvent;
      import flash.events.MouseEvent;

    • 5

      Press "Control" and "Enter" simultaneously to play the quiz.

Related Searches:

References

  • "Flash Professional CS5 Bible"; Todd Perkins; 2010

Resources

Comments

Related Ads

Featured