DragManager prevents mouse events of children *Updated*
来源:互联网 发布:linux脚本编写 编辑:程序博客网 时间:2024/05/19 11:47
I just ran into another strange behavior of flex. Lets say you have a VBox, with an image inside. When the user clicks the image, it should do some stuff, but when the user clicks (mousedown actually) the VBox it should start dragging. You would expect that when you click the image, both events are fired. This is true when you don’t invoke the dragmanager. If you call the dragmanager, it cancels out all further mouseEvents, thus preventing the code of the image clickhandler to execute.
I hear you thinking “why would you want something like this?”. Well, I’m rebuilding the tree component and I need to have a click event on the icon to open a node. Also I need a mousedown event on the node (icon and label) to enable dragging in the tree. When you call the dragmanager, the click event of the icon doesn’t come through (although sometimes it does…). I created a small test case, which you can view here (source available). Click on the small icon, it will start dragging it and write to the textarea that the mousedown event is received. Now disable the dragmanager and click again, you’ll see that now 2 events are captured.
The problem with this issue is that the mousedown event is fired before the click event, so you’ll never know if the user clicked the icon. Right now, I don’t really have a solution for this issue, maybe I’ll end up rewriting the dragmanager so that it won’t cancel out all events.
Update 03/27/08
I found a work around for this problem. You call the dragmanager at mouseMove, not at mouseDown. If you click now, the click event is fired and the dragmanager is not invoked. But make sure you set a boolean at mouseDown that dragging is allowed and set it to false at mouseUp. Otherwise, flex will allways drag if you move the mouse over the component.
/////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
mouseUp="_dragging = false"
mouseOver="_dragging = false;"
viewSourceURL="srcview/index.html">
<mx:VBox
id="box"
backgroundColor="#ff6600"
mouseDown="_dragging = true"
mouseMove="_boxDown(event)">
<mx:Image
id="img"
click="txt.htmlText += 'image.CLICK<br />'"
source="app.png" />
</mx:VBox>
<mx:CheckBox
selected="{this._dragEnabled}"
id="chb"
label="Enable dragmanager"
click="this._dragEnabled = chb.selected"/>
<mx:TextArea
height="100%"
id="txt" />
<mx:Script>
<![CDATA[
import mx.managers.DragManager;
import mx.core.UIComponent;
import mx.core.DragSource;
[Bindable]
private var _dragEnabled:Boolean = true;
[Bindable]
private var _dragging:Boolean = false;
private function _boxDown(event:MouseEvent):void {
if(!_dragging) return;
txt.htmlText += "vbox.MOUSEMOVE<br />"
if(!this._dragEnabled) return;
var ds:DragSource = new DragSource();
DragManager.doDrag(event.currentTarget as UIComponent, ds, event);
}
]]>
</mx:Script>
</mx:Application>
原文:http://blog.idsklijnsma.nl/dragmanager-prevents-mouse-events-of-children/
- DragManager prevents mouse events of children *Updated*
- Mouse Events
- test the mouse events
- D3 Mouse Events
- dragManager
- How to Hook the Mouse to Catch Events Outside of your application
- System Events and Mouse Messages
- adds events to the mouse
- 第18章 Images and Mouse Events
- Mouse wheel events, event filters, and QScrollArea
- Children of Bodom
- Descriptions of Wait Events
- Classes of Wait Events
- One of the Mouse Event
- Children of a Lesser Python
- Children of the Candy Corn
- Children of the Candy Corn
- Children of the Candy Corn
- 30岁要做的事情
- 13种时间管理的方法
- P2P之UDP穿透NAT的原理与实现 - 增强篇
- 实现类似与ArcMap中的split tool的功能-----用点打断线
- 为什么?
- DragManager prevents mouse events of children *Updated*
- ubuntu9.04的安装
- Silverlight融合ajax实现前后台数据交互
- MVC模式and so on
- petshop4中profile的配置
- 鼠标全局钩子
- MyEclipse自动生成的web项目部署后在TOMCATE正常,resin下无法访问
- 用户控件使用一例
- 设计模式练习:代理模式