Flex中如何通过监听Object对象mouseLeave事件检测鼠标是否进入/离开Flex应用的例子
By Minidxer | April 14, 2009
接下来的例子演示了Flex中如何通过监听Object对象mouseLeave事件,检测鼠标是否进入/离开Flex应用。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="top"
- backgroundColor="white"
- applicationComplete="init();">
- <mx:Style>
- Alert {
- modalTransparencyColor: black;
- modalTransparency: 0.6;
- }
- </mx:Style>
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- import mx.managers.PopUpManager;
- private var _isMouseInSWF:Boolean = false;
- private var alert:Alert;
- [Bindable]
- private function get isMouseInSWF():Boolean {
- return _isMouseInSWF;
- }
- private function set isMouseInSWF(value:Boolean):void {
- _isMouseInSWF = value;
- }
- private function init():void {
- stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMove);
- stage.addEventListener(Event.MOUSE_LEAVE, stage_mouseLeave);
- }
- private function stage_mouseLeave(evt:Event):void {
- isMouseInSWF = false;
- if (alert) {
- PopUpManager.removePopUp(alert);
- }
- alert = Alert.show("GONE");
- }
- private function stage_mouseMove(evt:MouseEvent):void {
- if (!isMouseInSWF) {
- if (alert) {
- PopUpManager.removePopUp(alert);
- }
- // alert = Alert.show("BACK");
- isMouseInSWF = true;
- }
- }
- ]]>
- </mx:Script>
- <mx:Label text="isMouseInSWF: {isMouseInSWF}" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Other, PopUpManager |
No Comments » |
Tags: Application, mouseLeave, mouseMove, PopUpManager, removePopUp, stage