开发者

How to get mouse and keyboard events, masked by PopUpManager

I am implementing an application timeout feature (flex4). What I am finding is that mouse and keyboard events, which I have listened to with :

FlexGlobals.topLevelApplication.addEventListener(MouseEvent.MOUSE_MOVE, resetLastActivity);
FlexGlobals.topLevelApplication.addEventListe开发者_StackOverflowner(KeyboardEvent.KEY_DOWN, resetLastActivity);

are being masked by the existence of any popup windows. The code is in a component, in the constructor. The component is added to the main application in the block.

How can I get these system generated events to not get stopped by PopUpManager display objects?

Thanks!


Try listening on the Stage instead of the topLevelApplication. access the stage using the stage property on the topLevelApplication

I think topLevelApplication formally returns an object, so you'll need to do something like this:

(FlexGlobals.topLevelApplication as Application).stage.addEventListener(MouseEvent.MOUSE_MOVE, resetLastActivity);
(FlexGlobals.topLevelApplication as Application).stage.addEventListener(KeyboardEvent.KEY_DOWN, resetLastActivity);

Update:

Keep in mind that the stage is not set in the topLevelApplication until that component's creationComplete event is fired. If you are adding event listeners to the stage in a non UI class; you have to make sure this is not done until creationComplete fires in the topLevelApplication.

To do this, add an event listener to the topLevelApplication's creationComplete method in the constructor.

(FlexGlobals.topLevelApplication.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationCompete);

If this is an MXML UIComponent, you can add that code in a preinitialize event handler instead of a constructor.

Then this would be the creation complete handler:

public function onCreationComplete(event:FlexEvent):void{
    (FlexGlobals.topLevelApplication as Application).stage.addEventListener(MouseEvent.MOUSE_MOVE, resetLastActivity);
    (FlexGlobals.topLevelApplication as Application).stage.addEventListener(KeyboardEvent.KEY_DOWN, resetLastActivity);
}


This works more elegantly without bothering creationComplete.

FlexGlobals.topLevelApplication.systemManager.addEventListener(MouseEvent.MOUSE_MOVE, resetSessionTimer);
FlexGlobals.topLevelApplication.systemManager.addEventListener(KeyboardEvent.KEY_DOWN, resetSessionTimer);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜