开发者

Is MouseEvent a class or an instance of a class or both?

I'm having trouble getting the hang of as3 syntax (php is the only other coding languag开发者_运维百科e I know)

mybutton.addEventListener(MouseEvent.CLICK, myListenerFunction);

function myListenerFunction(e:MouseEvent):void
{
     // function body
}

In this code it seems like MouseEvent is an instance of the class MouseEvent.

MouseEvent.CLICK

However in this code it seems like e is an instance of class MouseEvent

e:MouseEvent


MouseEvent.CLICK is a class's public constant which can be accessed everywhere with no need to create an instance. It's like public static variable in php class.

e:MouseEvent is an instance of MouseEvent class.

Check out MouseEvent class documentation http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/MouseEvent.html


MouseEvent.CLICK

This is reference to a static constant of the MouseEvent class. So to answer your question, MouseEvent here is a reference to a Class. The CLICK Constant might be defined within the MouseEvent Class something like this:

package flash.events {
    public class MouseEvent extends Event {
        ...
        public static const CLICK:String = "click";
        ...
    }
}

So writing:

trace(MouseEvent.CLICK);

Would output the String:

click


MouseEvent.CLICK is a static member of MouseEvent. It contains a string, which is the event name. You could also use addEventListener("click", myListenerFunction), though that is less safe. I guess they just needed somewhere to put that constant.

The MouseEvent-class instance contains information on what happened to trigger the event etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜