When doing a banner ad, I tend to code things different ways, depending on the situation. Sometimes laying out items on the timeline, sometimes adding items dynamically.

But no matter what, there is always an invisible clickTag button above it all allowing for the user to click through to the desired website.

However, a lot of the time, items below this invisible button require some sort of user interaction, such as a button which does something besides go to the website. If the invisible clickTag button is over this item, it will not register any mouse events.

This is fine if the items were added dynamically – we can just swap how they are layered on the display list so the clickTag button is below it. But if the underlying button is on the timeline, it becomes more problematic – A button under a button, or two buttons at the same time are a pain.

So I came up with a class which dynamically creates an invisible clickTag button, and allows you to add or remove items underneath it to look out for, and allow them to have user interaction.

Download PassiveClickTag (AS3)

To use, in your main class type the following code:

var bClickTag:PassiveClickTag = new PassiveClickTag(this.stage.stageWidth, this.stage.stageHeight);
bClickTag.addEventListener(PassiveClickTag.CLICK, clickHandler, false, 0, true); 
bClickTag.start();

This will set up an invisible clickTag button which calls the clickHandler() method on click.
Nothing else is needed besides the event handler itself, for example:

function clickHandler($event:Event):void { 
	  trace(_clickTag)
}

When you have a button or object below the clickTag button that needs to have MouseEvent access, type:

bClickTag.addButton( myUnderlyingItem );

And to remove, type:

bClickTag.removeButton( myUnderlyingItem ); 

Once started, an ENTER_FRAME event runs and looks through the added buttons to see if there is anything the mouse is over that needs any MouseEvents. If so, it disables the clickTag while that button is below, re-enabling it once the mouse is not over that item anymore.

Feedback is encouraged. If someone can come up with another way to do it that does not require an ENTER_FRAME, I would be interested to hear what you think.