为了实现degrafa创建的canvas上多个surface的单独选中拖动效果,狠狠研究了一下flex页面的鼠标事件!
Application页面事件:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
backgroundColor="#ffffff" xmlns:src="src.*" mouseDown="OnMouseDown(event)"
mouseMove="OnMouseMove(event)" mouseUp="OnMouseUp(event)"
xmlns:event="event.*" xmlns:eventtest="eventtest.*">
<eventtest:eventcanvas>
</eventtest:eventcanvas>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.MouseEvent;
//鼠标按下响应事件
public function OnMouseDown(event:MouseEvent):void
{
// trace("MOUSE DOWN");
// Alert.show("MOUSE DOWN");
}
public function OnMouseMove(event:MouseEvent):void
{
// trace("MOUSE Move");
}
//鼠标抬起响应事件
public function OnMouseUp(event:MouseEvent):void
{
//如果鼠标左键按下
// trace("MOUSE UP");
// Alert.show("MOUSE UP ");
}
]]>
</mx:Script>
</mx:Application>
在运行页任何位置点击鼠标,按下,移动和抬起事件都会正常响应。但是如果把事件定义在application页的script,而把侦听事件给application的一个canvas,那么点击canvas,无法响应它侦听的事件,必须给canvas上放一个button才能响应出事件。
Application页面事件:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
backgroundColor="#ffffff" xmlns:src="src.*" mouseDown="OnMouseDown(event)"
mouseMove="OnMouseMove(event)" mouseUp="OnMouseUp(event)"
xmlns:event="event.*" xmlns:eventtest="eventtest.*">
<eventtest:eventcanvas>
</eventtest:eventcanvas>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.MouseEvent;
//鼠标按下响应事件
public function OnMouseDown(event:MouseEvent):void
{
// trace("MOUSE DOWN");
// Alert.show("MOUSE DOWN");
}
public function OnMouseMove(event:MouseEvent):void
{
// trace("MOUSE Move");
}
//鼠标抬起响应事件
public function OnMouseUp(event:MouseEvent):void
{
//如果鼠标左键按下
// trace("MOUSE UP");
// Alert.show("MOUSE UP ");
}
]]>
</mx:Script>
</mx:Application>
在运行页任何位置点击鼠标,按下,移动和抬起事件都会正常响应。但是如果把事件定义在application页的script,而把侦听事件给application的一个canvas,那么点击canvas,无法响应它侦听的事件,必须给canvas上放一个button才能响应出事件。