如何给自定义的flash组件添加事件??

      flash As 2005-9-1 16:38:00
import mx.events.EventDispatcher;
class MyButton {
private var dispatchEvent:Function;
private static var _mixin1 = EventDispatcher.initialize(MyButton.prototype);
// Event Handler
private function Click():Void {
trace("onClick");
this.dispatchEvent({type:"onClick", target:this});
}
}
自问自答了:

类的代码如下:

class MyButton extends MovieClip {
private var clickEventObjArray:Array = undefined;
private var eventInfo:Object = undefined;
public function addEventListener(event:String, eventObj:Object):Void {
if (event == "click") {
clickEventObjArray.push(eventObj);
}
}
public function removeEventListener(event:String):Void {
if (event == "click") {
clickEventObjArray = new Array();
}
}
public function onRelease():Void {
for (var i = 0; i < clickEventObjArray.length; i++) {
clickEventObjArray[i].click(eventInfo);
}
}


组件实例名称是:Button1

代码如下:
Button1.onRelease = function() {
trace("!");
};

在组件实例上单击鼠标,打印出 !
标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}