Pop+Quiz

**I. Introduction**
Time to test some evil! Dr. Horrible has selected his recruits and now its time to start training. He needs you to design an on-line test to establish each recruits baseline evilness. Unlike the screening test, this one needs to print the results out to a file. Oh, and by the way, some of the other members of the Evil League of Evil are interested in using your system for testing their own recruits.

**II. Learning Objectives**
//**Knowledge**// //**Skills**//
 * Write to a file
 * Open a file

**III. Concepts**
Writing data to a file is pretty straight forward. Here is a simple example: code format="actionscript3" var file:File = File.desktopDirectory.resolvePath("temp.txt"); var filestream:FileStream = new FileStream; fileStream.open(file, FileMode.APPEND); fileStream.writeUTFBytes("Hello file!"); code
 * Reading and writing files**

Reading data is also straightforward. Just for fun, let's let the user choose which file to open: code format="actionscript3" function open:void{ try { var fileToOpen:File = new File; fileToOpen.addEventListener(Event.SELECT, fileSelected); fileToOpen.browseForOpen("Open"); } catch (error:Error) { trace("Failed:", error.message); } }

function fileSelected(event:Event):void { var stream:FileStream = new FileStream; stream.open(event.target as File, FileMode.READ); var fileData:String = stream.readUTFBytes(stream.bytesAvailable); } code You can learn much much more about files by reading the [|developer's guide on the AIR File API] and by looking at the language reference on [|File] and [|FileStream].

**IV. Scenario**
**Evil Tester**

**Use case** 1. Henchmen clicks Go to start the test (or clicks Load to load a different test) 2. FIrst question is displayed 3. Henchman clicks his/her answer 3. Henchman clicks next to display next question 4. After the last question, tester displays a "reset" button 5. Henchman clicks reset and is returned to start screen

**VI. Self-explain (Try it!)**
Go over each tag in the MXML program and explain out loud to yourself what it does. If you don't know exactly what the tag does, just try to guess for now.

**VII. Program Walkthrough (Try it!)**
create the interface for the question screen make a default question xml for now load in the questions and populate the screen add a next button to loop through add a start screen with a go button and and end screen with a reset button make the next button go to the end screen after the last question when the program starts up, make it open a log file to output data to [concept: FILE OUT] on each answer make it log add a load button to the start screen when user clicks on load button make it read in a questions file and use that instead of default