下拉菜单下面移动calloutbutton [英] dropdown following moving calloutbutton

查看:323
本文介绍了下拉菜单下面移动calloutbutton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flex的动作脚本问题。

我有一个是在屏幕上移动一个calloutbutton。 当我打开下拉(由一个点击)它停留在(只箭头移动)在屏幕上的相同位置。它不遵循calloutbutton的位置

我想这个下拉跟随calloutbutton的位置时,它已经移动(因为它当一个人点击该按钮时再次它已移动)。

我试图派遣一个MouseEvent.CLICK。这不可行。 也尝试开,然后再次关闭下拉列表中使用ActionScript唱closeDropDown()和openDropDown()。没有变化。

感谢

样品code(调用来自的creationComplete的init()):

 的creationComplete =的init();>
< FX:声明>
    <! - 将非视觉元素(例如,服务,价值的物品)在这里 - >
< / FX:声明>
< FX:脚本>
    <![CDATA [
        进口flash.events.MouseEvent;

        进口mx.events.DropdownEvent;

        私有函数的init():无效{
            VAR minuteTimer:定时器=新的定时器(1 * 1000);
            器minuteTimer.addEventListener(TimerEvent.TIMER,updateCalloutPosition);
            //启动计时器滴答声
            minuteTimer.start();
        }

        私有函数updateCalloutPosition(事件:事件):无效{
            myButton.closeDropDown();
            myButton.x = this.width *的Math.random();
            myButton.y = this.height *的Math.random();
// myButton.openDropDown();
            myButton.dispatchEvent(新的MouseEvent(MouseEvent.CLICK));
        }

        保护功能myButton_clickHandler(事件:MouseEvent)方法:无效
        {
            如果(myButton.isPopUp){
                myButton.closeDropDown();
            }
            其他 {
                myButton.openDropDown();
            }
        }

    ]]≥
< / FX:脚本>
< S:CalloutButton ID =myButton的点击=myButton_clickHandler(事件)>
&所述; /秒:CalloutButton>
 

解决方案

我尝试了一些替代方法,但openDuration和closeDuration是不工作的DropDownList的,如果它可以比下code可以帮助你实现。希望下面的code可以帮助你。

 < XML版本=1.0编码=UTF-8&GT?;
< S:应用的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
               XMLNS:S =库://ns.adobe.com/flex/spark
               的xmlns:MX =库://ns.adobe.com/flex/mx=了minWidth955了minHeight =600
               的creationComplete =的init()>
    < FX:声明>
        <! - 将非视觉元素(例如,服务,价值的物品)在这里 - >
        < S:ArrayCollection的ID =交流>
            < FX:字符串> AK< / FX:字符串>
            < FX:字符串> AL和LT; / FX:字符串>
            < FX:字符串> AR< / FX:字符串>
        < / S:ArrayCollection的>
    < / FX:声明>
    < FX:样式>
        @namespace的库://ns.adobe.com/flex/spark;
        @namespace MX库://ns.adobe.com/flex/halo;

        S | DropDownList的{
            openDuration:0;
            closeDuration:0;
        }
    < / FX:样式>
    < FX:脚本>
        <![CDATA [
            进口flash.events.MouseEvent;

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

            私人VAR storeVisible:布尔= FALSE;

            私有函数的init():无效{
                VAR minuteTimer:定时器=新的定时器(1 * 1000);
                器minuteTimer.addEventListener(TimerEvent.TIMER,updateCalloutPosition);
                minuteTimer.start();
            }

            私有函数updateCalloutPosition(事件:事件= NULL):无效{
                myButton.x = this.width *的Math.random();
                myButton.y = this.height *的Math.random();
                如果(myButton.isDropDownOpen)
                {
                    myButton.closeDropDown(假);
                    storeVisible = TRUE;
                }
            }

            私有函数updateComp():无效
            {
                如果(storeVisible)
                {
                    myButton.openDropDown();
                    storeVisible = FALSE;
                }
            }

        ]]≥
    < / FX:脚本>

    &所述氏:DropDownList中的id =myButton的的selectedIndex =0的dataProvider ={交流}upd​​ateComplete =updateComp()/>
< / S:用途>
 

Flex Actionscript question.

I have a calloutbutton that is moving on the screen. When I open the dropdown (by a click) it stays at the same position on the screen (only the arrow is moving). It does not follow the calloutbutton's position

I would like this dropdown to follow the position of the calloutbutton when it has moved (as it does when one clicks on the button again when it has moved).

I have tried to dispatch a MouseEvent.CLICK. It does not work. Tried also to open, then close again dropdown with actionscript sing closeDropDown() and openDropDown(). No change.

Thanks

Sample code (call init() from creationComplete) :

    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>

解决方案

I tried some workaround but openDuration and closeDuration is not working for DropDownList if it can be achieved than following code may help you. Hope following code may help you.

<?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>

这篇关于下拉菜单下面移动calloutbutton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆