flex 事件注册和鼠标拖动

flex 事件注册和鼠标拖动

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               applicationComplete="onApplicationComplete(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            protected function onApplicationComplete(event:FlexEvent):void{
                // 统一进行事件的注册;
                circle.addEventListener(MouseEvent.MOUSE_DOWN,dragOn);
                circle.addEventListener(MouseEvent.MOUSE_UP,dragOff);
            }
            protected function dragOn(event:MouseEvent):void{
                // 这样就可以实现circle跟随鼠标拖动;
                circle.startDrag();
            }
            protected function dragOff(event:MouseEvent):void{
                // 这样就停止了circle的跟随鼠标拖动;
                circle.stopDrag();
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    </fx:Declarations>
    <s:Group id="circle">
        <s:Ellipse width="100" height="100">
            <s:fill>
                <s:SolidColor color="#009900"/>
            </s:fill>
            <s:stroke>
                <s:SolidColorStroke color="#000000" weight="2" />
            </s:stroke>
        </s:Ellipse>
    </s:Group>
</s:Application>
原文地址:https://www.cnblogs.com/stono/p/4987376.html