user1005253
user1005253

Reputation: 404

Checking if Mouse Click was not in a MovieClip

I have number of movieClips on stage, with each having it's own Event Listener. Once Click/Touch the event is called each movie clip does something. For example one movieClip makes about 6 other movie clips visible.

What I want to do is, when the user Touch/Click somewhere else on stage, where there is no movieClip I want to know, so I can perform some actions such as make some movieClips invisible.

P.S the reason why I say Touch/Click is I'm developing this app for Android, however to make testing easier I'm currently testing everything in PC with MouseEvent, rather than TouchEvent. Once I get all the features working, I will switch over to TouchEvent and test it in mobile.

Many Thanks, Mike

Upvotes: 1

Views: 1708

Answers (2)

Chris
Chris

Reputation: 58132

I would just do a check, it's simple and quick and doesn't require adding code to alter propagation.

import flash.events.MouseEvent;

stage.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);

function onClick(e:MouseEvent):void 
{
    if(e.target == stage)
    {
        trace("click click");   
    }
}

Upvotes: 0

delosgatos
delosgatos

Reputation: 116

Add event listener to the stage. And in the event handlers of your inner movieclips use event.stopPropagation function to prevent bubble event to the container.

Upvotes: 2

Related Questions