因為需要在事件中帶入值
但AS3的架構嚴,沒辦法像AS2一樣想塞啥就塞啥
上網找了一些資料,基本上需要繼承Event再自行定義
學習了兩種方式
以下做個筆記
1.方法一
直接在New MyEvent時將值帶入
package com.core.util.event{
import flash.events.*;
public class MyEvent extends Event {
private var _info:Object;
public function MyEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
super(type, bubbles, cancelable);
this._info = info;
}
public function get eventInfo():Object {
return this._info;
}
public override function toString():String {
return formatToString("Event:", "type", "bubbles", "cancelable", "eventInfo");
}
}
}
2.方法二
另以一個方法設定值
package com.core.util.event{
import flash.events.*;
public class MyEvent extends Event {
private var _info:Object;
public function MyEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
super(type, bubbles, cancelable);
}
public function set createInfo(obj:Object):void {
this._info = obj;
}
public function get eventInfo():Object {
return this._info;
}
}
}
個人比較常用第一個
少寫幾行算幾行~XD
- May 03 Sat 2008 01:25
AS3自訂事件
全站熱搜
留言列表