有谁知道如何以编程方式放大flex3按钮的hitArea。有什么我可以重写的函数吗?按钮类中没有名为hitArea的函数。
我所做的就是,我已经为一个按钮创建了一个WHat皮肤。皮肤的形状由四个箭头组成。在箭头之间没有任何东西(意思是透明)。由于皮肤的形状,很难点击按钮。皮肤已经改变了按钮hitArea。我正在寻找的是一种方法,以扩大hitArea和改变的hitArea形状在一个正方形。(点击区域当然必须仍然是不可破坏的)。
有谁知道如何做到这一点吗?
谢谢
DJ
发布于 2010-08-14 07:18:39
我过去处理这个问题的方式是通过将alpha设置为0.001 (或类似的值)来使用几乎不可见的填充填充rect。这样按钮就会认为该区域是绘制的,因此可以点击,但它太透明了,用户看不见。这是可爱的/黑客,但它的工作。:)
发布于 2011-01-12 21:16:50
对于每个扩展UIComponent的对象(比如您的按钮),您可以使用assign a Sprite as a custom hitarea。我只需要向按钮添加一个creationComplete处理程序,绘制一个矩形子画面(宽度和高度等于按钮的宽度和高度),然后将其指定为按钮的新点击区域。
发布于 2011-03-21 09:12:34
这并不是特定于按钮的-但对于一般情况,您可以使用以下函数来扩展hitArea。
编辑:我刚刚为按钮添加了第二个答案,它使用正确的hitState而不是hitArea。
这将找到一个对象的边界,并创建一个命中区域,整个区域都比精灵的'extendBy‘大。只有正方形对象才能正常工作--但通常情况下,这应该可以很好地工作。对于更复杂的命中区域,如果你想通过编程来实现,你需要一些更复杂的东西。
addHitAreaToParent=true
adds the hit area to the parent (so child bounds don't change)
addHitAreaToParent=false (default)
adds the hit area to the sprite itself. the bounds of this sprite will change,
but if the sprite is moved inside its parent container the hit area will move too希望这能有所帮助!
public function extendHitArea(symbol:Sprite, extendBy:int, addHitAreaToParent:Boolean=false, visibleHitArea:Boolean=true) {
// get bounds of existing sprite
var bounds:Rectangle = addHitAreaToParent ? symbol.getBounds(symbol.parent) : symbol.getBounds(symbol);
// create hit area - extended by 'extendBy' all the way aroudn
var hitArea:Sprite = new Sprite();
hitArea.graphics.beginFill(0xCCFF00, .5);
hitArea.mouseEnabled = false;
hitArea.graphics.drawRect(bounds.x - extendBy, bounds.y - extendBy, bounds.width + (extendBy * 2), bounds.height + (extendBy * 2));
// add hit area either to the sprite itself (default) - or to the parent
(addHitAreaToParent ? symbol.parent : symbol).addChild(hitArea);
symbol.hitArea = hitArea;
// hide the hit area (by default)
hitArea.visible = visibleHitArea;
}https://stackoverflow.com/questions/3481037
复制相似问题