Previous Tip  |  Next Tip  |  Design Tips   | [Bill's Home]

127. Creating an Emulator

One of the best ways to train a person is to use an emulator of the system that they require training on. It doesn't quite match the real thing, but it can build-up confidence before the user actually uses it. Flash provides one of the best ways to develop an emulator as it has powerful text processing commands, and can integrate well with a browser. The following is a very simple example. If you type in HELP or ? it will show a basic help response, otherwise it will say command not recognised:

[Expand]

It uses three text windows: disp (where the previous commands are entered, and where the status of the command is shown), inp (the input command window) and prompt (which displays the prompt). The code is fairly simple:


disp.htmltext="<P>Bill's Emulator (c)bill@napier<BR>";
disp.background = true;
disp.multiline = true;
disp.border = false;
disp.type = "output";

pr.background = true;
pr.multiline = false;
pr.border = false;
pr.text=">";

Selection.setFocus("_root.inp");

inp.type = "input";
inp.background = true;
inp.multiline =true;
inp.border = false;

prompt.text=">";
str=inp.text;
inp.text=" ";

//setFontMenu();
inp.onChanged = function() {
str=inp.text;
trace("String is " + str);
for (i=0;i<str.length;i++)
{
if (str.charcodeat(i)==13)
{
str=str.slice(0,i); trace(str);
disp.scroll++;
prompt.text=">";
inp.text="";
if (str=="help" || str=="?") { disp.htmltext= disp.htmltext + "<P><B>HELP:</B> This will display this screen<P>"; }
else { disp.htmltext=disp.htmltext + "<P>Can't find command: " + str + "<BR>"; }
}
}

}