This next portion of the code is the actual display of the word. First, display the default image on the screen.

            //put the default image on the screen
            var currentFrame:DisplayObject;
            currentFrame = new defaultClass();
            currentFrame.x = 100;
            currentFrame.y = 50;
            rect.addChild(currentFrame);
          
            var selected:Sprite = button2;
                                    
            //string we will parse and spell out, initially an empty string
            var displayString:String = "";
          
            //speed for the video
            var speed:int;
          
            instruct.text = "Please select speed.";

These functions are called when one of the speed selector buttons is pressed.  The setSpeed function displays the highlighting textfield over the button and sets the speed that the images will display to the corresponding selection.

            /*
            * Set the speed of the display
            */
            function slowSpeed(e:MouseEvent):void
            {  
                setSpeed(700, 77, "Slow", button1);
            }
            function regSpeed(e:MouseEvent):void
            {
                setSpeed(500, 98, "Med", button2);
            }
            function fastSpeed(e:MouseEvent):void
            {
                setSpeed(200, 120, "Fast", button3);
            }
            /*
             * Set the speed that the parser displays the images
             */
            function setSpeed(newSpeed:int, yPos:int, text:String, selectedButton:Sprite):void
            {
                speed = newSpeed;
                highlight.x = 287;
                highlight.y = yPos;
                highlight.text = text;
                addChild(highlight);
                selected = selectedButton;
                speedSelected = true;
                if(!inQuiz)
                    instruct.text = "Please Input String to Read, then press Return."
                myText.addEventListener(KeyboardEvent.KEY_DOWN, enterPressed);
            }

This next function tests to see what the program should do when the user hits the enter key.  First, it checks to see if the user has inputted a string to be displayed, if so, it then displays that sequence of images.  Otherwise, if the user has selected quizMode, then the program will call the function doWork that will display that string.


            /*
             * Function to determine if the user has pressed enter, thereby indicating that it
             * is time to start the image sequence
             */
            function enterPressed(e:KeyboardEvent):void
            {
                //check to see if enter is pressed and that there is something in the input box.
                if(e.keyCode == Keyboard.ENTER && myText.text != "" && !inQuiz)
                {
                    doWork(myText.text.toLowerCase());
                }
                else if(e.keyCode == Keyboard.ENTER && inQuiz && test())
                {
                    if(myText.text.toLowerCase() == quizArray[quizIndex] && newWord)
                    {
                        debug.text = "Correct!";
                        quizCounter.wasCorrect();
                        numCorrect.text = "Correct: "+quizCounter.getCorrect();
                        newWord = false;
                    }
                    else if(newWord)
                    {
                        debug.text = "Sorry, incorrect.";
                        quizCounter.wasIncorrect();
                        numWrong.text = "Incorrect: "+quizCounter.getIncorrect();
                        newWord = false;
                    }
                    if(quizCounter.getIncorrect()+quizCounter.getCorrect()==quizCounter.getLength())
                    {
                        instruct.text = "Result: "+quizCounter.getCorrect()+"/"+quizCounter.getLength();
                        quizCounter.reset();
                        numWrong.text = "Incorrect:";
                        numCorrect.text = "Correct:";
                    }
                }
            }
            /*
            * Test the text in the input textbox to make sure it contains only proper a-z ascii characters
            */
            function test():Boolean
            {
                var toReturn:Boolean = true;
                for(var i:int = 0; i < myText.text.length; i++)
                {
                    if(myText.text.charCodeAt(i)<96 || myText.text.charCodeAt(i)>122)
                        toReturn = false;
                }
                return toReturn;
            }

This function actually displays the appropriate image in the window of the alphabetical handshape in the window. The way this program works is that one string is set as a display string. The first character of the string is displayed, then knocked off; this process is repeated until the entire string has been displayed.


            /*
            * display the appropriate picture in the main window
            * then remove the first character from the string we are displaying
            */
            function parseInput(e:TimerEvent):void
            {
                rect.removeChild(currentFrame);
                currentFrame = array[displayString.charCodeAt(0)-96];
                currentFrame.x = 100;
                currentFrame.y = 50;
                rect.addChild(currentFrame);
                displayString = displayString.substr(1);
            }
           
            //keeps a copy of the entire word being displayed
            var word:String = "";

This function doWork, takes a string and displays the sequence of images corresponding to the lettering of the word using the timer class within actionscript.

            /*
            * Sets the parser into motion, timed by the timer
            */
            function doWork(input:String):void
            {
                displayString = input;
                word = input;
                if(test())
                {
                    instruct.text = "";
                    var myTimer:Timer = new Timer(speed, displayString.length);
                    myTimer.addEventListener(TimerEvent.TIMER, parseInput);
                    myTimer.start();
                }
                else
                {
                    instruct.text = "Please make sure your input consists only of letters a-z.";
                }
            }