开发者

keydown event reusable code - how can I write it once and use anywhere in my flex application

I am new to flex framework.

I have created an application using flex framework 4.1 which is having various components that are shown to the end user in the form of a popup window using <mx:TitleWindow>.

This titlewindow is closed either on the click of the close button (displayed in it's titlebar) or by pressing the "escape key" on the keyboard.

I coded a functionality wherein I close the current TitleWindow whenever an 'esc开发者_如何转开发ape' button is pressed. Here is what I did.

On the keydown event of TitleWindow I called this function

private function detectescapekeypress(event:KeyboardEvent):void
{
    if(event.charCode == Keyboard.ESCAPE)
       PopUpManager.removePopUp(this);
}

But this function does not work when I define it in the main home screen of my application and call it using parentApplication.detectescapekeypress(event) on the keydown event of TitleWindow

I had to repeat this code for every TitleWindow that I have used in the project.

How can I write the above functionality only once and reuse it amongst various TitleWindow and other components so that the code for the same is not repeated across various components?

Note: Every TitleWindow that I am using has different code, scripts and layout in it.

Thanks


Why don't u just extend the TitleWindow component and add that functionality to your new custom component? Then use it everywhere instead of the original TitleWindow.

I assume u're using at least SDK 4.1 Create a new mxml file called for example CustomTitleWindow.mxml and paste the following http://www.copypastecode.com/68211/

Then change all your title windows to CustomTitleWindow.

P.S. Note that in order for the key event to be dispatched, the component must have focus.

blz

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜