Packagevegas.ui
Classpublic class KeyInspector
InheritanceKeyInspector Inheritance Object

The key inspector listenen all keyboard event of a specific InterativeObject display and indicates if a specific key is down or up (with the isDown and isUp methods). In AS3 the Key.isDown() and Key.isUp() method don't exist, this inspector use composition to emulate this feature.

Example :

     package examples
     {
         import vegas.ui.KeyInspector;
         
         import flash.display.Sprite;
         import flash.display.StageScaleMode;
         import flash.events.Event;
         import flash.geom.Point;
         import flash.ui.Keyboard;
         
         [SWF(width="980", height="720", frameRate="24", backgroundColor="#666666")]
         
         public class KeyInspectorExample extends Sprite
         {
             public function KeyInspectorExample()
             {
                 ////////
                 
                 ball = new Sprite() ;
                 
                 ball.graphics.beginFill( 0xFF0000 ) ;
                 ball.graphics.drawCircle(0, 0, 24) ;
                 
                 ball.x = 50 ;
                 ball.y = 50 ;
                 
                 addChild( ball ) ;
                 
                 ////////
                 
                 key = new KeyInspector( stage );
                 
                 ////////
                 
                 stage.scaleMode = StageScaleMode.NO_SCALE ;
                 stage.addEventListener( Event.ENTER_FRAME, enterFrame );
             }
             
             protected var ball:Sprite ;
             
             protected var key:KeyInspector ;
             
             public var speed:Point = new Point(10,10) ;
             
             protected function enterFrame( e:Event ):void
             {
                 if ( key.isDown( Keyboard.LEFT ) )
                 {
                     ball.x -= speed.x ;
                 }
                 
                 if ( key.isDown( Keyboard.RIGHT ) )
                 {
                     ball.x += speed.x ;
                 }
                 
                 if ( key.isDown( Keyboard.UP ) )
                 {
                     ball.y -= speed.y ;
                 }
                 
                 if ( key.isDown( Keyboard.DOWN ) )
                 {
                     ball.y += speed.y ;
                 }
                 
             }
         }
     }
     



Public Properties
 PropertyDefined By
  target : InteractiveObject
The interactive display object reference on which to listen for keyboard events.
KeyInspector
Public Methods
 MethodDefined By
  
KeyInspector(display:InteractiveObject)
Creates a new KeyInspector instance.
KeyInspector
  
clear():void
Clear the inspector key code buffering.
KeyInspector
  
isDown(keyCode:uint):Boolean
To test whether a key is down.
KeyInspector
  
isUp(keyCode:uint):Boolean
Tests whether a key is up.
KeyInspector
Property Detail
targetproperty
target:InteractiveObject

The interactive display object reference on which to listen for keyboard events.


Implementation
    public function get target():InteractiveObject
    public function set target(value:InteractiveObject):void
Constructor Detail
KeyInspector()Constructor
public function KeyInspector(display:InteractiveObject)

Creates a new KeyInspector instance.

Parameters
display:InteractiveObject — An interactive display object on which to listen for keyboard events. To catch all key events, this should be a reference to the stage.
Method Detail
clear()method
public function clear():void

Clear the inspector key code buffering.

isDown()method 
public function isDown(keyCode:uint):Boolean

To test whether a key is down.

Parameters

keyCode:uint — code for the key to test.

Returns
Boolean — true if the key is down, false otherwise.

See also

isUp()method 
public function isUp(keyCode:uint):Boolean

Tests whether a key is up.

Parameters

keyCode:uint — code for the key to test.

Returns
Boolean — true if the key is up, false otherwise.

See also