Button element (used with Interface module)

Description:

This element is used to create buttons within an interface. Buttons can be either image based, or text buttons with coloured backgrounds. Buttons can be grouped together to create the equivalent of radio buttons in a form. So when one button is pressed in, all the others in the group will not be pressed in. Otherwise, they act as normal form buttons, and will pop out after being pressed.

To use:

The code for this element is included in the interface module, linked as follows:

<script language="Javascript" src="gamelib_interface.js"></script>

You then instantiate a button object by using one of the following methods depending if it's a text type button, or an image type button (the parameters are commented in the examples, you can obviously have all the parameters on the same line, but I've spaced them out to help make things more readable.):

// Example of a text button

  myButton=new In_Button(
   155, // x position
   128, // y position
   80, // width
   20, // height
   "text", // type of button
   "myButton6.setLegend('Fred')",// statement to be executed when button clicked
   "Button 4", // button text
   "#aaaa88", // button mouse out color
   "#ddddbb", // button mouse over color
   "#ffff00", // button mouse click color
   "#000000", // button border color
   "#000000", // button font color
   2 // font size for button text
  );

// Example of an image button

  myButton=new In_Button(
   110, // x position
   125, // y position
   60, // width
   20, // height
   "image", // type of button
   "alert('Button 1 pressed!')", // statement to be executed when button clicked
   "../images/button1.gif", // button initial image
   "../images/button1.gif", // button mouse out image (usually same as above)
   "../images/button1hi.gif", // button mouse over image
   "../images/button1click.gif" // button mouse click image
  );

List of methods for Buttons

click
clearRadio
makeRadio
setAction
setColors
setImages
setLegend

Descriptions of methods for Buttons

MethodParametersDescription
click(none) The equivalent of clicking the button with the mouse. This will cause the button's action to fire. If it's a radio button, then it will be pressed down and the others in the group will return to/stay in their up state.
clearRadio(none) This method destroys a radio group. If any button in a group has this method called, the entire group disappears, so no buttons formerly in the group will be linked.
makeRadioList of Button Objects This will create a radio button group between this button and the buttons listed as the argument to this method. Once the buttons have been grouped together, their behaviour will change so that only one can ever be pressed at a time, and the last button to be pressed will stay in the pressed state until another from the same group is pressed. Their actions still function as normal.
setActionString Sets the button's action. This can be any legal javascript statement, but would normally be a function call.
setColorscolor, color, color This method can only be used with text type buttons. It changes the normal, mouseover and clicked colours for the button, in that order. All 3 colors must be specified.
setImagesURL, URL, URL This method can only be used with image type buttons. It changes the images used for the buttn's normal, mouse over and clicked states, in that order. All 3 image URLs must be specified.
setLegendString This method can only be used with text type buttons. It changes the text on the face of the button.