开发者

AS3 Tracing a Class extended from the Event Class

I have created a class (extends the Event class) for use in one of my projects. If I trace the custom event object in the called function I get 'Event' as the type, but if I trace a TimerEvent, or MouseEvent, etc, I get TimerEvent or MouseEvent... Let me demonstrate:

var c:CustomObject = new CustomObject();
c.addEventListener(CustomEvent.ON_SEND_MESSAGE,fnc);

function fnc(e:CustomEvent) {
    trace(e);
}

This traces:

[Event type="onSendMessage" bubbles=false cancelable=false e开发者_如何学编程ventPhase=2]

While this code:

var f:Timer = new Timer(2000);
f.addEventListener(TimerEvent.TIMER,th);
f.start();

function th(e:TimerEvent):void {
    trace(e);
}

traces this:

[TimerEvent type="timer" bubbles=false cancelable=false eventPhase=2]

Why does my custom event class not trace [CustomEvent ...]


You need to override the toString() method:

public override function toString(): String
{
   return "[CustomEvent]";
}

Disclaimer: Haven't used flash/flex in a while. But I think that is correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜