target vs currentTraget

When working with MouseEvents the event object provides two properties that refer to object that originated the event: target and currentTarget. The right choice between these two is almost always currentTarget.

The problem with target is that often it is not the object that you think it is. The target property is the object that was actually clicked. This can any object nested within the MovieClip that was clicked, and often not the MovieClip itself, which is what you are most often expecting.

The currentTarget property on the other hand is the object that registered the event. Which is almost always what you are expecting.

So for general use it should always be currentTarget. The target property does provide an interesting function but in most cases it’s not what you think it is.

Leave a Reply

Your email address will not be published. Required fields are marked *