Hello Everyone,
Recently I was working on one Adobe AIR enterprise application, and I faced one problem that may be occurred to many developers of Adobe Flash Platform.
I want to share that with other guys, that they might be needed or may face this problem.
In my application, I had a one popup and that popup was listening for some shortcuts keys to open another popup. And shortcuts were basically with the combination with Alter Key (Alt+A, Alt+E, Alt+P etc.).
When I press one shortcut, say Alt+A, one another child popup was opened. And in that popup I have to set focus on one textinput when it is opened.
So when I was pressing Alt+A, one default character was written in that textinput. For example, ‘1’ for Alt+A.
And more different characters for different combination of keys with Alter Key.
So this was the problem with different shortcuts and also if we are in one textinput in main popup, if any shortcut key is pressed then that default character was also written in that textinput.
So I found two solutions for solving this problem.
First, I found that, do not set focus directly, while opening that child popup of shortcut.
For example,
private function openPopup():void
{
var myPopup:MyChildPopup = new MyChildPopup();
PopUpManager.addPopUp(myPopup, this, true);
PopUpManager.centerPopUp(myPopup);
myPopup.setFocus(); //wrong method
}
Instead of setting forcus directly, use callLater functionLike,
private function openPopup():void
{
var myPopup:MyChildPopup = new MyChildPopup();
PopUpManager.addPopUp(myPopup, this, true);
PopUpManager.centerPopUp(myPopup);
callLater(setPopupFocus, [myPopup]); //right method
}
public function setPopupFocus(popup:MyChildPopup):void
{
popup.setFocus();
}
So this call later function will be called when that dispatcher key event will be over, and that character will be not listened by new opening popup's textinput.But still the problem was that if we press any key with alter combination in any textinput, it was writing that default character in textinput.
So, I used event.preventDefault(); to stop writing text with alter key in textinput when alter key is pressed.
So I had created one custom textinput which was listening keyDown method of textinput and do not write any character if alter key is pressed.
So here is my class of that custom textinput.
package
{
import flash.events.KeyboardEvent;
import spark.components.TextInput;
public class CustomTextInput extends TextInput
{
public function CustomTextInput()
{
super();
}
override protected function keyDownHandler(event:KeyboardEvent):void
{
if(event.altKey)
event.preventDefault();
}
}
}
So, I hope this will help to some developers to solve the problem.


