Complex Renderer Mouse Handling

If you have a renderer that has many different components and you need to mouse out and mouse over events when user moves mouse over the renderer, you have two options. Use only one element of your complex renderer to detect mouse over and mouse out. If this is not acceptable the other solution is to set mouseChildren to false on the renderer and use hit test in order to detect mouse interaction on different renderer elements. Check out the example of complex renderer event handling done with hit test approach.
private function onListRendererAdd(event:RendererExistenceEvent):void {

var renderer:DisplayObjectContainer = event.renderer as DisplayObjectContainer;
if (renderer) {

renderer.mouseChildren = false;

renderer.addEventListener(MouseEvent.MOUSE_OVER, onListRendererOver);
renderer.addEventListener(MouseEvent.MOUSE_OUT, onListRendererOut);
renderer.addEventListener(MouseEvent.CLICK, onListRendererSelection);
renderer.addEventListener(MouseEvent.CLICK, onListRendererInfo);

}

}

private function onListRendererRemove(event:RendererExistenceEvent):void {

var renderer:IEventDispatcher = event.renderer as IEventDispatcher;
if (renderer) {
renderer.removeEventListener(MouseEvent.MOUSE_OVER, onListRendererOver);
renderer.removeEventListener(MouseEvent.MOUSE_OUT, onListRendererOut);
renderer.removeEventListener(MouseEvent.CLICK, onListRendererSelection);
renderer.removeEventListener(MouseEvent.CLICK, onListRendererInfo);
}

}

private function onListRendererOver(event:MouseEvent):void {

// This event will be dispatched only once when user rolls over the renderer.

}

private function onListRendererOut(event:MouseEvent):void {

// This event will be dispatched only once when user moves from the renderer.

}

private function onListRendererSelection(event:MouseEvent):void {

var renderer:DisplayObject = event.target;
if (renderer && renderer.selectionControl.hitTestPoint(event.stageX, event.stageY)) {

// Check if the mouse was on the selection control when the click event was dispatched.
// This way we know that the mouse click was on the selection control.

}

}


private function onListRendererInfo(event:MouseEvent):void {

var renderer:DisplayObject = event.target;
if (renderer && renderer.infoControl.hitTestPoint(event.stageX, event.stageY)) {

// Check if the mouse was on the info control when the click event was dispatched.
// This way we know that the mouse click was on the info control.

}

}

Comments on this post

Crateed the greatest articles, you have.
Hey, that's the graetest! So with ll this brain power AWHFY?
mOaYnV <a href="http://arbpumzdbgtc.com/">arbpumzdbgtc</a>
That's not just logic. That's really ssenible.
<a href="http://www.remedyshopping.net/">tramadol</a> 213166 <a href="http://www.remedy-stores.com/">buy cialis generic</a> qgw
<a href="http://www.insuraccount.net/">cheap life insurance</a> ivp <a href="http://www.insurproducts.net/cheap_auto_insurance.html">cheap auto insurance</a> gfml
<a href="http://www.findmedsonline.net/">ou acheter du viagra a paris</a> 03439 <a href="http://www.medsearchguide.com/">cialis</a> =-]]]
<a href="http://www.insurerslist.net/">business insurance</a> 916165 <a href="http://www.insursonline.com/">eastwood auto insurance</a> pbw
<a href="http://www.medicaoffers.com/">cheap levitra online vardenafil</a> qor <a href="http://www.findmedspartners.com/">levitra</a> =-((
<a href="http://www.meds-shopping.com/">Cialis</a> 227 <a href="http://www.mymedsguide.com/">compare levitra and viagra</a> 830574
<a href="http://www.insurers-info.com/">online auto insurance</a> 01397 <a href="http://www.insurersdeals.com/">life insurance</a> 3447
<a href="http://www.insurersmarket.net/">car insurance</a> >:-DD <a href="http://www.insurs-online.com/">auto insurance quotes</a> bcblec
<a href="http://www.insurproviders.com/">auto insurance quotes</a> 2164 <a href="http://www.insursonline.com/">cheap auto insurance</a> nkgses
<a href="http://www.shoppills.net/">topamax+wellbutrin</a> 8[[ <a href="http://www.medsonweb.com/">cymbalta without prescription</a> cflqr
<a href="http://www.centiprix.net/">order propecia online</a> yfxwfb <a href="http://www.shoppills.net/">topamax</a> wmfr
These aren't the mom's footwear and perhaps they are not your own tiny sister's. replica shoes,These sneakers are only to the woman which does not need to observe the girl footwear in another's feet.
Hey, klielr job on that one you guys!
I love these artilces. How many words can a wordsmith smith?
jwBBAz <a href="http://gmyelclbprpl.com/">gmyelclbprpl</a>
Super eicxted to see more of this kind of stuff online.
Kudos! What a neat way of thkiinng about it.
What a great resuorce this text is.
Tn Requin,puma Homme speed cat,basket Nike Tn

Chaussures,Nike TN,Chaussures Nike,pas cher Nike Air Max

2010,chaussures puma,Pas cher Nike TN Requin,Chaussures

Nike Tn Requin,TN Requin,Tn Requin Pas Cher,Nike TN

Requins,Chaussures TN,Timberland chaussures,Air Max 95

,Nike TN: timberland Chaussures
Chaussures Femme Chaussures Homme Chaussures Enfant Nike

TN requin enfant
nouvelle nike tn requin
http://www.nousbest.com
REQUIN TN
http://www.nousbest.com
NIKE AIR MAX
http://www.nousbest.com
puma chaussures
http://www.nousbest.com
Chaussures Air Max 91,Femmes Air Max 91,Hommes Air Max 91,Chaussures Air Max 95,Hommes Air Max 95,Femmes Air Max 95,Chaussures Air Max 180,Chaussures Air Max Bw,Hommes Air Max Bw,Femmes Air Max Bw,Chaussures Air Max Ltd,Femmes Air Max Ltd,Hommes Air Max Ltd,Chaussures Air Max Tn,Hommes Air Max Tn,Femmes Air Max Tn,Chaussures Air Max 87,Femmes Air Max 87,Hommes Air Max 87.
Air Max 2012
http://www.airmaxpascher-2012.com
Air Max Pas Cher 2012
http://www.airmaxpascher-2012.com
Nike Pas Cher 2012
http://www.airmaxpascher-2012.com
http://www.birkenstock-shoe.com/
http://www.birkenstock-shoe.com/
http://www.birkenstock-shoe.com/
In recent years Louis Vuitton Handbagsthis inland port city of nearly 300,000Louis Vuitton Handbags people has earned several distinctions, none Chanel Handbagsof them good. Twice atop Forbes'Coach Factory Outlet list of America's Most Miserable Louis Vuitton PursesCities ... Second highest violent-crimeChanel Handbag rate in California ... Second highest home-foreclosure rate Boss Beltsof all major U.S. metro areas. Now, Stockton is on the Coach Factory Onlineverge of another dubious benchmark: bankruptcy.Louis Vuitton Purses In its third straight year of fiscal emergency,Coach Factory Online the city faces a deficit of as high asCoach Factory Outlet $38 million on its $165 million general fundCoach Factory Stores budget. As required by state law,Coach Outlet Store the city
http://www.polosralphlaurensale.fr/Polo-Sacs-%C3%A0-main-c116_p1.html
http://www.polosralphlaurensale.fr/Ralph-Lauren-Femmes-c115_p1.html
http://www.polosralphlaurensale.fr/Ralph-Lauren-Hommes-c85_p1.html

Post a comment

Embed any code between [code] [/code] tags
captcha image   Reload