Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Flex KeyboardEvent properties 
 

In this example working of properties charCode and keyCode of KeyboardEvent class under flash.events package is demonstrated.

 

Flex KeyboardEvent properties

                         

In this example working of properties charCode and keyCode of KeyboardEvent class under flash.events package is demonstrated.
These properties generate numeric values whenever a key is pressed. With these values generated, the key pressed can be detected.
Before using these properties, the event listeners and event handlers for the keyboard event have to be created and applied first. Now, in the example listeners are created on the flex TextArea control, therefore whenever a key is pressed inside this control the listener of the event will be triggered.
Now, an event handler with name eventInfo  is created and inside which the statements containing properties charCode and keyCode are coded.

Property charCode generates the ASCII character set value for the value associated with the key. Here the key value is the alphabet value that the key holds.
For example : charCode of 'a' will be different to the charCode of 'A'.
       

Property keyCode generates the numeric value of the key on the keyboard. This value is unique for each key on the keyboard. 
For example : There are two keys on the keyboard to write a number three (3).  Now the charCode generated value of the keys will match but the keyCode generated value will differ because both the keys possess same values but are located at different places on the keyboard.

Key.mxml

<?xml version = '1.0' encoding = 'utf-8'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml' 
            initialize = 'eventListener_1();'>
  <mx:Script> 
  
    import mx.controls.*;
  
    public function eventListener_1():void{
      tA.addEventListener(KeyboardEvent.KEY_UP, eventInfo);
      tA.addEventListener(KeyboardEvent.KEY_DOWN, eventInfo);
    }
      
      
    public function eventInfo(event:KeyboardEvent):void{
      var str:String = "Key code : " + event.keyCode +
             "\nChar code : " + event.charCode;
      tx.text = str;
    }  
  
    public function alert(event:Event):void{
      Alert.show("Event result\n" + tx.text);
    }    
      
  </mx:Script> 
  
  <mx:Style>
    .rachel {color : #996600}
    TextArea {font-size : 18pt}
  </mx:Style>
  
  <mx:Panel title = 'Rachel Weisz' backgroundColor = '#FFCC99
        paddingTop = '50' paddingBottom = '50' 
        paddingRight = '50' paddingLeft = '50'> 
        
      <mx:Button label = 'Click me' click = 'alert(event)
          color = '#6600CC' styleName = 'rachel'/>
              
      <mx:TextArea id = 'tA' styleName = 'rachel'/>
      <mx:Text id = 'tx' color = '#003333'/>
  
  </mx:Panel> 

</mx:Application>

 

Key.swf

 

Download the code

                         

» View all related tutorials
Related Tags: c gui com class controls ui select button style control io components sed implementation component definition tag name using this

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.