基础篇:事件的发送和处理

       在ActionScript3.0中,Event类属性有:type、cancelable、target、currentTarget、eventphase、bubles

Event方法有:clone()、toString()、stopPropogation()、stopImmediateProgation()、preventDefault()、isDefaultPrevented()和formatToString()

管理事件监听器

注册事件监听器:zc.addEventListener(MouseEvent.CLICK,onHandler)

删除事件监听器:sc.addEventListener(MouseEvent.CLICK,onHandler)

检查事件监听器:jc.hasEventListener(MouseEvent.CLICK)

       所有的事件都属于flash.events包内。常用的有鼠标事件(MouseEvent),键盘事件(KeyboardEvent),时间事件(TimerEvent),帧循环(ENTER_FRAME)事件。

以下做了几个简单的实例:

var zc:Sprite=new Sprite();
zc.graphics.beginFill(0xff0000);
zc.graphics.drawRect(0,0,100,20);
zc.graphics.endFill();

addChild(zc);
zc.x=275	
zc.y=200
zc.doubleClickEnabled = true 

var lobel:TextField = new TextField();
lobel.text='双击按钮';
lobel.doubleClickEnabled=true;
zc.addChild(lobel);

zc.addEventListener(MouseEvent.DOUBLE_CLICK,onHandler);
function onHandler(e:MouseEvent):void {
	lobel.text="你双击了按钮";

}
//创建一个可以拖动的显示对象
 
  

var zc:Sprite=new Sprite();
zc.graphics.beginFill(0xff0000);
zc.graphics.drawCircle(100,100,20);
zc.graphics.endFill();
addChild(zc);
zc.buttonMode=true;
zc.addEventListener(MouseEvent.MOUSE_DOWN,onHandler);
zc.addEventListener(MouseEvent.MOUSE_UP,onrelease);
function onHandler(e:MouseEvent):void {
 e.target.startDrag();

}
function onrelease(e:MouseEvent):void {
 e.target.stopDrag();
}

//自定义鼠标的样式
var zc:Sprite=new Sprite();
zc.graphics.lineStyle(2,0x00FF00,2)
zc.graphics.moveTo(100,100)
zc.graphics.lineTo(145,124)
zc.graphics.lineTo(127,148)
zc.graphics.lineTo(100,113)
zc.graphics.lineTo(100,100)
addChild(zc);
stage.addEventListener(MouseEvent.MOUSE_MOVE,Move);
function Move(evt:MouseEvent):void {
 zc.x=evt.stageX
 zc.y=evt.stageY
 evt.updateAfterEvent()
 Mouse.hide()
}
 
  
 
 

转载于:https://www.cnblogs.com/zhaomin214/archive/2010/12/02/1893988.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值