A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Flash UI Components

  1. #1
    Junior Member
    Join Date
    Oct 2002
    Posts
    3

    Flash UI Components

    All,
    The standard on the web for triggering component actions is the enter key. All the flash UI Components seem to use the space bar. Is there any way to change it so the enter key triggers the components actions.

    Example,
    Web pushbutton - on focus, enter key or space bar triggers events
    Flash UI Pushbutton - on focus, only the space bar triggers events

    Regards,
    John

  2. #2
    Senior Member
    Join Date
    May 2002
    Location
    The Great Northwest
    Posts
    380

    You can alter the button component code slightly...

    Open your library (F11).
    find the PushButton component (under Flash UI Components).
    Double click on the PushButton Icon.
    Click on the first frame of the actions layer.
    Press F9 (opens the actions editor).
    press Control F (opens the find dialog).
    type in this phrase "Key" (without the quotes of course).
    Press enter.

    You should see something like this:
    Code:
    FPushButtonClass.prototype.myOnKeyDown = function( )
    {
    	if (Key.getCode() == Key.SPACE && this.pressOnce == undefined ) {
    		this.onPress();
    		this.pressOnce = 1;
    	}
    }
    
    FPushButtonClass.prototype.myOnKeyUp = function( )
    {
    	if (Key.getCode() == Key.SPACE) {
    		this.onRelease();
    		this.pressOnce = undefined;
    	}
    }
    This is where the SPACE is defined. If you change the above code to this:
    Code:
    FPushButtonClass.prototype.myOnKeyDown = function( )
    {
    	if (Key.getCode() == Key.SPACE || Key.getCode() == Key.ENTER && this.pressOnce == undefined ) {
    		this.onPress();
    		this.pressOnce = 1;
    	}
    }
    
    FPushButtonClass.prototype.myOnKeyUp = function( )
    {
    	if (Key.getCode() == Key.SPACE || Key.getCode() == Key.ENTER) {
    		this.onRelease();
    		this.pressOnce = undefined;
    	}
    }
    you will find the enter key will work just as the spacebar key works.

    NOTE: this will not work in the Control + Enter testing environment because ENTER is defined to goto the next frame. It will work if you open the swf. It should work in the browser if the Flash movie has focus.
    God bless you!

  3. #3
    Junior Member
    Join Date
    Oct 2002
    Posts
    3

    That worked, and a note for others

    Thanks, for the help.

    Note for combobox:

    For the combobox I made a slight modification to make the enter key the action key. I just wrapped the below part of the if statement in paren's and the combobox's actions triggers when using the enter key.

    I changed line 442 from:
    else if ( (Key.isDown(Key.ENTER) || (Key.isDown(Key.SPACE) && !this.editable)) && this.opened) {

    to:
    else if ( ((Key.isDown(Key.ENTER) || (Key.isDown(Key.SPACE)) && !this.editable)) && this.opened) {

    Jake

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