A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: How to press 'Enter' Key and call a function?

Threaded View

  1. #2
    Senior Member
    Join Date
    Nov 2005
    Posts
    192
    http://code.google.com/p/bigroom/wiki/KeyPoll
    http://bigroom.googlecode.com/files/KeyPoll.zip

    put the KeyPoll.as file in the folder with your main swf.

    From your document class, the main one, do

    Code:
    import flash.ui.keyboard;
    
    ...
    public static var Key:KeyPoll= new KeyPoll(stage);
    to call it from your otherclasses/functions you use.
    Code:
    if("Document class name".Key.isDown(Keyboard.ENTER)){
         call function
    }
    Alternatively, you can make your own Keys.as class that simply has the key codes for the key code you need like this:

    Code:
    package 
    {
    	
    	public class Keys 
    	{
    		
    		public function Keys() 
    		{
    			
    		}
    		public var Left:int = 37;
    		public var Up:int = 38;
    		public var Right:int = 39;
    		public var Down:int = 40;
    	}
    	
    }
    Use another public static variable for Keys like the KeyPoll.

    EDIT: I forgot you need to put stage in the KeyPoll parameters
    Last edited by Flyingcow; 07-02-2009 at 03:55 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center