[an error occurred while processing this directive]

Explore key & mouse with Flex



On this web page you will to know how to determine for a key is pressed or not when an event occurs. In the example below two flex controls CheckBox and Button and two flex containers HBox and VBox created. Also two MouseEvent class events click and mouse over are used. Example below is coded to track the pressing of two keys shift and alt with define events CLICK and MOUSE_OVER respectively.

Function addChild  in the code is used to bring the flex controls to generate inside the flex containers. 
Function addEventListener is used to add or invoke the respective mouse events on the containers.

Syntax for using above functions:

control_id.addEventListener(MouseEvent.CLICK/MOUSE_OVER, a_function_name);








<?xml version = '1.0'?>
  xmlns:mx = 'http://www.adobe.com/2006/mxml'

  import mx.controls.Button;
  import mx.controls.CheckBox;
  public function createControls():void{
    var ch0:CheckBox = new CheckBox();
    ch0.label = 'Anjelina jolie'
    var ch1:CheckBox = new CheckBox();
    ch1.label = 'Alicia Silverstone'
ch0.addEventListener(MouseEvent.MOUSE_OVER, removeCheckBoxes);
ch1.addEventListener(MouseEvent.MOUSE_OVER, removeCheckBoxes);

    var bt0:Button = new Button();
      bt0.label = 'rachel';
    var bt1:Button = new Button();
      bt1.label = 'neo';
bt0.addEventListener(MouseEvent.CLICK, removeButtons);
bt1.addEventListener(MouseEvent.CLICK, removeButtons);
  public function removeCheckBoxes(event:MouseEvent):void{
      event.currentTarget.toolTip = 'Alt + mouse'
        ' arrow to get rid of this Control';
  public function removeButtons(event:MouseEvent):void{
      event.currentTarget.toolTip = 'Shift + click to'
      ' get rid of this Control';
  <mx:VBox id = 'vertical' >
    <mx:HBox id = 'horizonBox'/>

    label = 'create  flex controls
    click = 'createControls()
    color = '#660000'







Download the code



[an error occurred while processing this directive]