0

Flex Actionscript 问题。

我有一个在屏幕上移动的标注按钮。当我打开下拉列表(通过单击)时,它会停留在屏幕上的相同位置(只有箭头在移动)。它不跟随标注按钮的位置

我希望此下拉菜单在移动时跟随标注按钮的位置(就像在移动时再次单击按钮时一样)。

我试图发送一个 MouseEvent.CLICK。这没用。还尝试打开,然后再次关闭下拉菜单,使用 actionscript 唱 closeDropDown() 和 openDropDown()。没变。

谢谢

示例代码(从 creationComplete 调用 init()):

    creationComplete="init();">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import flash.events.MouseEvent;

        import mx.events.DropdownEvent;

        private function init():void {
            var minuteTimer:Timer = new Timer(1*1000);
            minuteTimer.addEventListener(TimerEvent.TIMER, updateCalloutPosition);
            // starts the timer ticking
            minuteTimer.start();                
        }

        private function updateCalloutPosition(event:Event):void {
            myButton.closeDropDown();
            myButton.x = this.width * Math.random();
            myButton.y = this.height * Math.random();
//              myButton.openDropDown();
            myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
        }

        protected function myButton_clickHandler(event:MouseEvent):void
        {
            if (myButton.isPopUp) {
                myButton.closeDropDown();
            }
            else {
                myButton.openDropDown();
            }
        }

    ]]>
</fx:Script>
<s:CalloutButton id="myButton" click="myButton_clickHandler(event)">
</s:CalloutButton>
4

1 回答 1

0

我尝试了一些解决方法,但 openDuration 和 closeDuration 不适用于 DropDownList 如果可以实现,那么下面的代码可能会对您有所帮助。希望下面的代码可以帮助你。

<?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" minWidth="955" minHeight="600"
               creationComplete="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <s:ArrayCollection id="ac">
            <fx:String>AK</fx:String>
            <fx:String>AL</fx:String>
            <fx:String>AR</fx:String>
        </s:ArrayCollection>
    </fx:Declarations>
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/halo";

        s|DropDownList {
            openDuration: 0;
            closeDuration: 0;
        }
    </fx:Style>
    <fx:Script>
        <![CDATA[
            import flash.events.MouseEvent;

            import spark.components.supportClasses.DropDownListBase;
            import spark.components.supportClasses.TextBase;
            import spark.events.DropDownEvent;
            import spark.skins.spark.DropDownListSkin;
            import spark.utils.LabelUtil;

            private var storeVisible:Boolean = false;

            private function init():void {
                var minuteTimer:Timer = new Timer(1*1000);
                minuteTimer.addEventListener(TimerEvent.TIMER, updateCalloutPosition);
                minuteTimer.start();                
            }

            private function updateCalloutPosition(event:Event = null):void {
                myButton.x = this.width * Math.random();
                myButton.y = this.height * Math.random();
                if(myButton.isDropDownOpen)
                {
                    myButton.closeDropDown(false);
                    storeVisible = true;
                }
            }

            private function updateComp():void
            {
                if(storeVisible)
                {
                    myButton.openDropDown();
                    storeVisible = false;
                }
            }

        ]]>
    </fx:Script>

    <s:DropDownList id="myButton"  selectedIndex="0" dataProvider="{ac}" updateComplete="updateComp()"/> 
</s:Application>
于 2012-06-19T11:21:18.490 回答