小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

在FLEX中创建不可以拖拽的ALERT组件.

重点是在鼠标按下的时候调用事件处理程序的stopImmediatePropagation() 方法.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/21/creating-an-undraggable-alert-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white">

    
<mx:Script>
        
<![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();
            }
        
]]>
    
</mx:Script>

    
<mx:ApplicationControlBar dock="true">
        
<mx:Button label="Draggable Alert"
                click
="draggableAlert();" />
        
<mx:Button label="Undraggable Alert"
                click
="undraggableAlert();" />
    
</mx:ApplicationControlBar>

</mx:Application>

来自:http://blog.flexexamples.com/2008/03/21/creating-an-undraggable-alert-control-in-flex/

posted on 2008-03-30 19:28  『小小菜鸟』  阅读(343)  评论(0编辑  收藏  举报