继续体会1中的目标
移动canvas上的多个surface中的一个,通过eventcanvas调用testmouseevent。只有当鼠标按在“动”字上,或按在矩形框上才能触发鼠标的MouseEvent.MOUSE_DOWN事件,按在surface的任何空白处都没有作用。继续探索在surface上任意位置 按下鼠标如何响应事件......
testmouseevent.as代码如下
package eventtest
{
import com.degrafa.GeometryGroup;
import com.degrafa.GraphicText;
import com.degrafa.Surface;
import com.degrafa.geometry.RegularRectangle;
import com.degrafa.paint.SolidStroke;
import flash.events.MouseEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import mx.controls.Alert;
public class testmouseevent extends Surface
{
[Bindable]
public var WhiteStroke:SolidStroke = new SolidStroke();
protected var eachcolggw:GeometryGroup = new GeometryGroup();//每个列都需要一个gg,一个边框矩形
protected var eachcolrecw:RegularRectangle;
private var isMouseDown:Boolean = false;
private var frompoint:Point=new Point;
private var topoint:Point =new Point;
public function testmouseevent()
{
super();
addEventListener(MouseEvent.MOUSE_DOWN, OnMouseDown);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
addEventListener(MouseEvent.MOUSE_MOVE, OnMouseMove);
/* addEventListener(MouseEvent.MOUSE_UP, OnMouseUp);
addEventListener(MouseEvent.MOUSE_OVER, onMouseIn); */
}
public function loadevent():void
{
eachcolggw.x = 0;
eachcolggw.y = 10;
eachcolggw.height=1000;
eachcolrecw= new RegularRectangle(0, 0,100, 1000);
eachcolrecw.stroke = WhiteStroke;
eachcolggw.geometryCollection.addItem(eachcolrecw);
var gt:GraphicText=new GraphicText;
gt.text='动';
gt.x=0;
gt.y=2;
eachcolggw.addChild(gt);
eachcolggw.target = this;
eachcolggw.addEventListener(MouseEvent.CLICK,this.ggclick);
/* eachcolggw.addEventListener(MouseEvent.MOUSE_OVER,this.onMouseIn);
eachcolggw.addEventListener(MouseEvent.MOUSE_OUT,this.onMouseOut); */
}
public function ggclick(event:MouseEvent):void
{
Alert.show("click gg");
}
//鼠标移动响应事件
public function OnMouseMove(event:MouseEvent):void
{
//如果鼠标左键按下
if (isMouseDown)
{
//计算移动距离并更新矩阵
topoint.x= event.stageX;
topoint.y= event.stageY;
var finalm:Matrix= new Matrix;
finalm.tx = topoint.x; //- frompoint.x;
finalm.ty = topoint.y; //- frompoint.y;
this.transform.matrix=finalm;
trace(finalm.tx);
}
//trace("MOUSE move surface");
trace("MOUSE move surface");
}
//鼠标抬起响应事件
public function OnMouseUp(event:MouseEvent):void
{
//如果鼠标左键按下
if (isMouseDown)
{
topoint.x= event.stageX;
topoint.y= event.stageY;
isMouseDown = false;
trace(topoint.x);
//Alert.show(topoint.x.toString());
}
trace("MOUSE up surface");
}
protected function onMouseIn(even:MouseEvent):void
{
// if(even.currentTarget is GeometryGroup)
if(even.currentTarget is Surface)
WhiteStroke.color=0x00ff00;
}
protected function onMouseOut(even:MouseEvent):void
{
// if(even.currentTarget is GeometryGroup)
if(even.currentTarget is Surface)
WhiteStroke.color=0x000000;
}
private function OnMouseDown(event:MouseEvent):void {
trace("MOUSE DOWN surface");
// Alert.show("MOUSE DOWN surface");
isMouseDown = true;
frompoint.x=event.stageX;
frompoint.y=event.stageY;
trace(frompoint.x);
}
}
}
分享到:
相关推荐
一个开源的degrafa绘图工具,里面自带自动生成svg,flex实现,简单易懂,供大家学习
用flex解析SVG,使用degrafa框架显示出来
Degrafa3.1源码 配合 FLEX绘制行政区域地图源码使用 两个工程依赖关系
flex开发的画图框架Degrafa 近来需在flex画些简单的图形,根据朋友推荐使用了Degrafa,但是官方没有提供离线的文档下载,于是自己制作了一下。 文档的所有版权均属http://www.degrafa.com 详细情况请查看degrafa的...
好用的Degrafa.CHM,方便用flex绘制矢量图
flex开发的画图框架Degrafa 近来需在flex画些简单的图形,根据朋友推荐使用了Degrafa,但是官方没有提供离线的文档下载,于是自己制作了一下。 文档的所有版权均属http://www.degrafa.com 详细情况请查看degrafa的...
NULL 博文链接:https://smartblack.iteye.com/blog/385683
Degrafa扩展就是在FLEX中增加了对矢量数据的动态处理,包括动态添加,删除和修改,并支持SVG的路径格式数据, 因此只需要对现有的SVG数据进行一些必要的转换(以后会有工具支持,但现在只能手工完成),就可以将SVG...
1.Degrafa 是flex中的一个开源关系图表框架。birdeye就是基于degrafa写的。 2.amstockchart和amcharts是TourDeFlex中下载的一个收费的图形报表框架。下载的是具有短期(好像是3个月)的试用期,并且带有其公司logo,...
只有一个sign05.mxml,需要加入其它FLEX工程使用 博文链接:https://smartblack.iteye.com/blog/388933
Flex on Java Bernerd Allmon and Jeremy Anderson MEAP Began: May 2008 Softbound print: July 2010 (est.) | 375 pages ISBN: 1933988797 Part 1: Getting started 1. Some Flex with your Java 2. Beginning...
flex3的Degrafa 做的流程图,适合初学者探讨
NULL 博文链接:https://angrycoder.iteye.com/blog/1436586
4. Connecting to Web Services Part 2: Strengthening the backend 5. BlazeDS remoting and logging 6. Flex messenging Part 3: Going above and beyond 7. Securing and personalizing your application 8...
基于Actionscript3.0,强大的矢量图形绘制类库
NULL 博文链接:https://madfroghe.iteye.com/blog/1020454
NULL 博文链接:https://cwfmaker.iteye.com/blog/544190
Degrafa框架已经非常接近在FLEX中动态显示和操作SVG文档了,通过一些简单的转换