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

133. Adding a Help Window

One way to enhance the emulator is to add a help window. In the following case a window is created which is then made into a movie. This window consists of a text area, a scrollbar component, a blue bar at the top and an exit button. The whole window is then defined as a movie, which in this case is named h. The advantage of making it a movie is that it has a _visible property. At the start of the movie the h._visible prameter is set to false, and then, when the user clips on the help button it is made true.

After Exit button is then set with the following:

on (press)
{
_root.h._visible=false;
_root.help_flag=false;

}

If you want to try it out, here's the complete movie:

 

Expand

This is achieved by storing the cmdline in a buffer, which is then scrolled through:

var cmdhistory = new Array();
var cmdval=0;
var cmdptr=0;

myListener.onKeyDown = function () {

if (Key.getAscii()==8)
{
str=cmdline;
if (str.length==1) str="";
else str=str.slice(0,str.length-1);
cmdline=str;
}
else if (Key.getCode()==Key.UP)
{
if (cmdptr>0) cmdptr--;
cmdline=cmdhistory[cmdptr];
}

else if (Key.getCode()==Key.DOWN)
{
if (cmdptr<cmdval) cmdptr++;
cmdline=cmdhistory[cmdptr];
}

else if (Key.getAscii()==Key.ENTER)
{
test1();
inp1.text="";
cmdline="";
cmdptr=cmdval;
}
else cmdline=cmdline+chr(Key.getAscii());

 

The current number of commands in the buffer is stored in cmdval, and the current position of the buffer is stored in cmdptr. When the UP arrow is pressed (Key.UP), the cmdptr is decremented, and when the DOWN arrow is pressed (Key.DOWN) the cmdptr is incremented.When the user pressed ENTER, the cmdptr is made equal to the cmdval.