Dear flash coders,

I'm struggling since a week already with
several elements in my application not
acting as I want them to do. And they
all could be reduced to a rectangle button
which has a TextField on top of it and
which should lighten up on a mouse over
and scale down on a mouse down event.

I have prepared a very simple test code
which demonstrates my problem:
   http://pastebin.com/m848fe2d
(also pasted it at the bottom of this mail).

You can see the problem if you left-click
on my button and then move the pointer
away without releasing it and then release:

private function handleMouseOut(event:MouseEvent):void {
        //if (this != event.target)
                //return;
        scaleX = scaleY = old_scale;
        rect.filters = SHADOW;
}

The TextField will receive the mouse out
event and make my button to pop up to
early (i.e. the mouse pointer is still inside
my button, but it is already in up state).

And if I remove the 2 comments above
then the scale of the button will get wrong,
because it will be set in mouse over event
and my button will get smaller and smaller

Thank you for any hints
Alex

PS: here is my test code:

package {
        import flash.display.*;
        import flash.events.*;
        import flash.text.*;
        import flash.filters.*;

        public class MyButton extends Sprite {
                private static const    SHADOW:Array = [ new DropShadowFilter(8,
                    80, 0x000000, 0.4, 32, 32, 1, 1, false, false, false) ];
                private static const    GLOW:Array = [ new GlowFilter(0xFF0000,
                    0.5, 36, 36, 1, 1, false, false) ];

                private var             rect:Shape;
                private var             old_scale:Number;

                public function MyButton() {
                        rect = new Shape();
                        rect.graphics.beginFill(0x00FF00);
                        rect.graphics.drawRect(-100, -100, 200, 200);
                        rect.graphics.endFill();
                        rect.filters = SHADOW;
                        addChild(rect);

                        var label:TextField = new TextField();
                        label.width = 100;
                        label.height = 50;
                        label.selectable = false;
                        label.border = true;
                        label.text = 'MyButton';
                        label.x = -label.textWidth/2;
                        label.y = -label.textHeight/2;
                        addChild(label);
                        addEventListener(MouseEvent.MOUSE_OVER, 
handleMouseOver);
                        addEventListener(MouseEvent.MOUSE_OUT, handleMouseOut);
                        addEventListener(MouseEvent.MOUSE_DOWN, 
handleMouseDown);
                        addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
                        addEventListener(MouseEvent.CLICK, handleMouseClick);
                }

                private function handleMouseOver(event:MouseEvent):void {
                        old_scale = scaleX;
                        rect.filters = GLOW;
                }

                private function handleMouseOut(event:MouseEvent):void {
                        //if (this != event.target)
                                //return;
                        scaleX = scaleY = old_scale;
                        rect.filters = SHADOW;
                }

                private function handleMouseDown(event:MouseEvent):void {
                        old_scale = scaleX;
                        scaleX *= 0.95;
                        scaleY *= 0.95;
                        rect.filters = null;
                }

                private function handleMouseUp(event:MouseEvent):void {
                        scaleX = scaleY = old_scale;
                        rect.filters = GLOW;
                }

                private function handleMouseClick(event:MouseEvent):void {
                        trace('MyButton clicked');
                }
        }
}
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to