Add a Button Click Function

Then we add a button click function.

You can copy this code from this page or download the source file here.

/**
 * Click  a button
 * @param  id  id attribute of the button to click
 * @return     true if there was no exception, false otherwise
 */
public function clickButton(id:String):Boolean {
  var btn:Button, retval:Boolean = false;
  try {
    btn = Button(getElementById(id));
    btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
    retval = true;
  }
  catch(e:Error) {
  }
  return retval;
}