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 Listener 
 

Example below demonstrates the working of KeyboardEvent listeners.

 

Flex KeyboardEvent Listener

                         

Example below demonstrates the working of KeyboardEvent listeners. In the example when certain specific keys are pressed the function eventListener invokes the functions neo and trinity. These specific keys are shift and ctrl which when pressed together opens a web page url. Also listener for keys are created using conditional statements and with these listeners when ever the boolean condition becomes true, an alert box is generated.

keyListeners.mxml

<?xml version = '1.0'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml' 
              initialize="eventListener()">
  <mx:Script>
    <![CDATA[
    
    public function eventListener():void{
      application.addEventListener(KeyboardEvent.KEY_UP, neo);    
      this.addEventListener(KeyboardEvent.KEY_UP, trinity);
    }
    
    public function neo(eve:KeyboardEvent):void{
                
      var CtrlKey:Boolean = eve.shiftKey;
        if(CtrlKey){
          var ShiftKey:Boolean = eve.shiftKey;
          if(ShiftKey){          
var url_0:URLRequest = new URLRequest("http://www.roseindia.net/flex");
            navigateToURL(url_0);
          }  
        }
          
      }
    
      import mx.controls.Alert;
      public function trinity(eve:KeyboardEvent):void{
txt.text = magic(eve.charCode" (" + String(eve.charCode")" 
+ magic(eve.keyCode" (" + String(eve.keyCode")";
        var power:int = eve.keyCode;  
        
        if(100 < power < 105)
          Alert.show("Welcome to roseindia\n" + txt.text);
      }
        
      
  public function magic(IntVal:int):String {
        if (IntVal > 47 && IntVal < 58) {
            var strIntVals:String = "0123456789";
            return strIntVals.charAt(IntVal - 48);
        else if (IntVal > 64 && IntVal < 91) {
            var strCaps:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            return strCaps.charAt(IntVal - 65);
        else if (IntVal > 96 && IntVal < 123) {
            var strLow:String = "abcdefghijklmnopqrstuvwxyz";
            return strLow.charAt(IntVal - 97);
        else {
            return IntVal.toString();
        }
    }        
  
    
    
    ]]>
  </mx:Script>
  
  <mx:Style>
    .eve {color : #660000}
    TextArea {font-size : 18pt}
  </mx:Style>
  
  
  <mx:Canvas backgroundColor = '#CCFF00' width = '100%
                    height = '100%'>
    <mx:TitleWindow title = 'roseindia.net
      showCloseButton = 'true' width = '40%' height = '30%'>
    
       <mx:TextArea id = 'txt' width = '80%
             height = '50%' styleName = 'eve'/>
       <mx:Text id = 'tnt' color = "#CCFFFF"/>
    </mx:TitleWindow>
  </mx:Canvas>
  
</mx:Application>    

 

keyListeners.swf

when the ctrl + shift is pressed following url (http://www.roseindia.net/flex) web page opens in you default browser

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.