Text based action adventure

Hello, I’m currently working on an action adventure game and have run into some issues. I am using flash CS4 and AS3. On the stage I have created a user input text field with the instance name of textbox and a button with the instance name of btn. I’m trying to set it up so that when the user types in a word that word is cross referenced with an array and a function is run. I have noticed that some times the functions are not run in the order there typed. For example if I type “enterdoor. lookaround.” Than the following is traced.

" you have entered the door.
.
you are looking around, but don’t see anything.
. "

Which is good but if I reverse the order and type “lookaround. enterdoor.” then I receive the following.

"you are looking around, but don’t see anything.
.
.
you have entered the door. "

Also if I were to type “gobacklookaroundenterdoor” then the following is displayed.

“go back
you have entered the door.
you are looking around, but don’t see anything.”

Notice that the function “enterdoor” is run before “lookaround” even thou “lookaround” was typed first.

Also if I were to type “enterdoorlookaround enterdoorlookaround” then the following is displayed.

"you have entered the door.
you are looking around, but don’t see anything.
you are looking around, but don’t see anything.
you have entered the door. "

I cant seem to figure out why the functions are not run in the order they are typed by the user. Not sure if this helps but I have determined that if a function is typed 3 times or more then it only returns the function twice. For instance if I were to input “enterdoorenterdoorenterdoor” then the following is displayed.

"you have entered the door.
you have entered the door. "

I would also like for the user to have the option of typing a function as many times in a row as needed. It seems to me that I’m missing some thing simple. I was thinking if I change the commands “array” to an “associative array” it might process the functions in the correct order. It seems to me that the commands array is being compared to the inputholder array. If we switch the order in which the too arrays are compared would that fix the issue? Sorry but this problem seems to be a bit out of my grasp and any help would be great. Here’s the code I have so far.

this.stop();
import flash.events.*;
btn.addEventListener(MouseEvent.CLICK,textChanged)

var inputHolder:Array = [];

var commands:Array = [“enterdoor”, “walk”, “goback”, “lookaround”, “lookup”, “dot”, “dot2”];

var lastText:String = “”;

var empty:String = textbox.text = “”;

var textChangeDelta:int = 0;

function textChanged(e:Event):void {

var patt:RegExp = /[.]|[!]{1,}/g;

var allText:String = textbox.text.replace(patt, “dot”);

for each(var command:String in commands) {
while (allText.indexOf(command) != -1) {

var index:int = allText.indexOf(command);
if (!inputHolder[index]) {
inputHolder[index] = command;
} else {
inputHolder[index+5] = command;
}
allText = allText.replace(command, “”);
}
}
}

btn.addEventListener(MouseEvent.CLICK,processInput );

function processInput(e:MouseEvent = null):void {
textbox.text = “”;
for each(var command:String in inputHolder) {
try {
thiscommand;
} catch (e:Error) {
sorrySay(command); continue; //wont be needed once you define all the functions
}
} inputHolder = [];
}

function sorrySay(word:String):void {
textbox.appendText("Sorry, " + word + " is not a command yet.
");
}
function lookaround():void {
textbox.appendText( "you are looking around, but don’t see anything.
" );
}

function enterdoor():void {
textbox.appendText( "you have entered the door.
" );
}

function dot():void {
textbox.appendText( ".
" );
}

function dot2():void {
textbox.appendText( "!
" );
}
function goback():void {
textbox.appendText( "go back
" );
}