- 最后登录
- 2024-6-3
- 注册时间
- 2009-10-16
- 阅读权限
- 100
- 积分
- 18803
- 纳金币
- 17488
- 精华
- 1
|
Cancel Bubble (Interactive Behavior)
Summary
Prevents a certain type of event from propogating to ancestor objects.
Category
Latest Behaviors
Author
Gavin Kistner
Difficulty
(Reference)
Time to Complete
5 Minutes
Downloads
Click Here
to download the associated files.
(This document covers version 1.0.1 of the 'Cancel Bubble' behavior, current as of 2005-Feb-11)
Description
When mouse events initiate for an object, by default they ‘bubble’ to the parent object, and then the grandparent, great-grandparent, (and so on) all the way up to the Scene.
Sometimes, you may want to ‘catch’ the events for a child object and stop them from bubbling up. For example, assume you have the following scene:
Scene
Layer
Robot Arm 1 Model
Select on Click (a behavior)
Robot Arm 2 Model
Select on Click (a behavior)
The goal here is to allow either arm to be selected with the mouse. However, event bubbling means that if you click on
Robot Arm 2 Model
, the onMouseClick event will bubble up to
Robot Arm 1 Model
, causing it to also be selected.
Attaching this behavior and setting
Event to Catch
to
Mouse Click
fixes the problem:
Scene
Layer
Robot Arm 1 Model
Select on Click (a behavior)
Cancel Bubble
Robot Arm 2 Model
Select on Click (a behavior)
Cancel Bubble
(Alternatively, you can modify your
Select on Click
behavior to return false at the end of its
onMouseClick
handler; this will also prevent the bubble from occurring.)
Various other behaviors cancel bubbling for certain events, such as Selection Group, Focusable, Draggable, and Tumble.
Basic Properties
Event to Catch
What event should be prevented from bubbling?
Demonstration
View Demonstration Project
Download Project File
|
|