Good Afternoon Everyone,

AM I correct in that it is ok to use event.target if the target movie is a stand alone object. But I need to use event.currentTarget if the movie clip has children inside?

Dani AI

Generated

Short answer: was on the right track and and are pointing to the same core idea. The important distinction comes from the AS3 event flow: the event is dispatched by the deepest interactive object under the pointer (the target) and then travels to parent objects where listeners run (the listener sees that parent as currentTarget). For simple, standalone clips the two are the same; when a clip contains children they often differ.

Practical implications and gotchas: use currentTarget when you want to operate on the object that actually registered the listener (safe to cast and manipulate). Use target when you are doing event delegation and need to know which specific child was clicked — but always check the child’s runtime type before casting to avoid runtime errors (text fields and internal shapes can appear as the target). mouseChildren = false (as noted) forces the container to be the interactive object, which can simplify handling.

Example patterns (AS3):

function onClick(e:MouseEvent):void {
    // safe reference to the object that owns the listener
    var owner:DisplayObject = DisplayObject(e.currentTarget);

    // if you need the actual clicked child, guard the cast
    if (e.target is MovieClip) {
        var clicked:MovieClip = MovieClip(e.target);
        // handle child-specific logic
    }

    // detect clicks directly on the owner vs a child
    if (e.target == e.currentTarget) {
        // clicked the owner itself
    }
}

Extra tips: if you want to prevent bubbling use stopPropagation() or add the listener in the capture phase when appropriate. Prefer attaching listeners to the element you intend to control; use delegation only when it simplifies code. These practices avoid class-cast errors and make behavior predictable when children are present.

Recommended Answers

All 2 Replies

Member Avatar for Member #334542

event.currentTarget to target the root of the movieclp, and if you want to target the clips inside the movieclip then use the event.target.

there is also DisplayObject.mouseChildren property which turns on and off mouse events for children inside the DisplayObject.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.