I Want my keyboard to respond when i press ENTER in Flex 2.0

I was reading some adobe forums this weekend, and came across this, and it seems like something i would use in the futures…

Here is the original item

<mx:Script>

<![CDATA[

import mx.controls.Alert ;

import flash.events.* ;

public function doEnter(event:KeyboardEvent):void

{

if(event.keyCode == 13)

{

Alert.show(“You pressed Enter”);

}

else

{

Alert.show(“You pressed :”+event.charCode);

}

}

]]>

</mx:Script>

<mx:Button id=“bt” label=“press any key” click=“assign1(event);” keyDown=“doEnter(event);”/>

2 comments on this post.
  1. sudha:

    please let me know as to how can i use the key board event, for an alert box which is inside the init() called by the application tag.

  2. admin:

    I thought an Alert box by default had it’s button set to be the defaultButton…

    but if your using it on the init of the application, your flash app won’t have access to the keyboard until you click on the app at least once.

    I’ve heard that swfObject gets rid of this issue… but i’m not sure, i’ve never tried it… (i’ve used swfObject, but never to get rid of the clicking on the app first issue, it was always just to ease the pain of changing the template)

    so anyway, try using swfObject and replacing in your index.template.html file use swf object instead of the default stuff that adobe profides to see if it works for you.

    Axel

Leave a comment