【问题标题】:Prevent certain child(ren) from affecting MouseEvent hitbox防止某些孩子(ren)影响 MouseEvent hitbox
【发布时间】:2013-09-13 12:22:17
【问题描述】:

我有一个用作按钮的影片剪辑。在这个动画剪辑中是一个大阴影,当鼠标悬停在按钮上时会显示出来。我的问题是这个阴影影响了鼠标悬停,并导致 mouseOver 和 mouseOut 事件的“捕获”区域比我想要的要大得多。

我已尝试禁用该子级的鼠标事件以及我能想到的尽可能多的 mouseEnabled 和 mouseChildren 组合。

是否有可能阻止某些元素影响其父级的鼠标悬停属性,或者只是定义一个自定义的命中框以供影片剪辑使用?

【问题讨论】:

    标签: actionscript-3 mouseevent mouseover


    【解决方案1】:

    您可以使用hitArea 属性,但实际上也可以使用mouseEnabledmouseChildren 进行控制,所以您走在正确的轨道上:

    假设您有一个名为“buttonMC”的影片剪辑,其中包含两个分别称为“clickableMC”和“shadowMC”的影片剪辑实例。

    通过在 shadowMC 上将 mouseChildren 和 mouseEnabled 都设置为 false,您不能直接在该实例上监听鼠标事件。但是,点击 shadowMC 仍然会触发点击 buttonMC。为了防止在 buttonMC 上将 mouseEnabled 设置为 false。请注意,对于 buttonMC,mouseChildren 仍应为 true。

    在按钮上将 mouseEnabled 设置为 false 并使其仍可点击可能听起来很奇怪,但可以将 mouseEnabled 视为确定显示对象的“图形”内容是否应可点击的标志。当 shadowMC 的 mouseChildren 和 mouseEnabled 设置为 false 时,就事件而言,影片剪辑的行为就像是图形(形状)。

    【讨论】:

    • 不幸的是,在按钮本身上禁用了鼠标启用它只是停止工作。我正在使用带有这些按钮的第三方 API,所以不知道它依赖什么。 HitArea 工作得很好,所以你仍然可以得到滴答声
    • 听起来按钮类在内部将 mouseChildren 设置为 false 和/或不包含任何扩展 InteractiveObject 的子项。听起来你最好使用 hitArea。
    • mouseEnabled 有官方文档吗?
    • 是的,在docs
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 2019-09-25
    相关资源
    最近更新 更多