基础篇:事件的发送和处理
?????? 在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();
}
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
總結
以上是生活随笔為你收集整理的基础篇:事件的发送和处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wxPython 笔记(3)基本结构
- 下一篇: WPF 文本呈现(2)