天天看点

Creating an undraggable Alert control in Flex

The following example shows how you can create a Flex Alert control that isn’t draggable by listening for the <code>mouseDown</code> event and calling the <code>stopImmediatePropagation()</code> method in the event handler.

Full code after the jump.

<a></a>

&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;!-- http://blog.flexexamples.com/2008/03/21/creating-an-undraggable-alert-control-in-flex/ --&gt;

&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

        layout="vertical"

        verticalAlign="middle"

        backgroundColor="white"&gt;

    &lt;mx:Script&gt;

        &lt;![CDATA[

            import mx.controls.Alert;

            private function draggableAlert():void {

                Alert.show("Drag me!");

            }

            private function undraggableAlert():void {

                var alert:Alert = Alert.show("Drag me!");

                alert.addEventListener(MouseEvent.MOUSE_DOWN, alert_mouseDown, true);

            private function alert_mouseDown(evt:MouseEvent):void {

                evt.stopImmediatePropagation();

        ]]&gt;

    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;

        &lt;mx:Button label="Draggable Alert"

                click="draggableAlert();" /&gt;

        &lt;mx:Button label="Undraggable Alert"

                click="undraggableAlert();" /&gt;

    &lt;/mx:ApplicationControlBar&gt;

&lt;/mx:Application&gt;

继续阅读