Reputation:
This is a situation I run into a lot but never seem to find a good solution. I have movieclips that I scale up slightly on rollover, but if you hover over the edge of the movieclip it just sits there and flickers, continuously receiving mouseOver and mouseOut events. How do you deal with this? Again, it's usually a problem when tweening the scale of a movieclip or button.
my_mc.addEventListener(MouseEvent.MOUSE_OVER, mOver);
my_mc.addEventListener(MouseEvent.MOUSE_OUT, mOut);
private function mOver(m:MouseEvent) {
TweenLite.to(m.target, .2, { scaleX:1.1, scaleY:1.1} );
}
private function mOut(m:MouseEvent) {
TweenLite.to(m.target, .2, { scaleX:1, scaleY:1} );
}
Upvotes: 0
Views: 1839
Reputation: 1392
I know what you mean: the animation itself generates unwanted input events as the clip expands/contracts bringing the cursor over or out of the clip's resized hitTest area.
Couple of ideas:
my_mc.addEventListener(MouseEvent.MOUSE_OVER, _animate);
my_mc.addEventListener(MouseEvent.MOUSE_OUT, _animate);
private function _animate(event:MouseEvent):void
{
var mc:Sprite = event.target as Sprite;
var animScale:Number = (event.type == MouseEvent.MOUSE_OVER) ? 2 : 1;
TweenLite.to(mc, 0.5, {
onStart: function():void {
mc.removeEventListener(MouseEvent.MOUSE_OVER, _animate);
mc.removeEventListener(MouseEvent.MOUSE_OUT, _animate);
},
scaleX: animScale,
scaleY: animScale,
onComplete: function():void {
mc.addEventListener(MouseEvent.MOUSE_OVER, _animate);
mc.addEventListener(MouseEvent.MOUSE_OUT, _animate);
}
});
}
Upvotes: 1