Flex 3:带有 PopUpButton 的圆形菜单

发布于 2024-08-04 14:54:50 字数 1843 浏览 4 评论 0原文

所以我有一个 PopupButton,当我单击该按钮时,我希望弹出的菜单具有圆角。我该怎么做呢?

更新: 我发现了与我想要做的类似的更新,可以在以下页面上找到:

http://blog.flexmonkeypatches.com/2007/10/08/flex-rounded-menues-using-masking/comment-page-1/

唯一的区别是我用 PopUpButton 显示菜单。到目前为止,这就是我的自定义菜单:

package {

    import flash.display.Sprite;

    import mx.controls.Menu;
    import mx.events.MenuEvent;

    public class MyMenu extends Menu {

        public function MyMenu() {
            super();
            addEventListener("menuShow", onMenuShow);
        }

        private function onMenuShow(e:MenuEvent):void {
            callLater(maskRoundedCorners,[e]);
        }


     private function maskRoundedCorners(e:MenuEvent):void {

                var menu:Menu = e.menu as Menu;
                menu.cacheAsBitmap=false;

                if (!menu.mask){
                    var maskx:uint = menu.x;
                    var masky:uint = menu.y;
                    var maskw:uint = menu.getExplicitOrMeasuredWidth();
                    var maskh:uint = menu.getExplicitOrMeasuredHeight();
                    var rad:int = menu.getStyle("cornerRadius") * 2;

                    var roundRect:Sprite = new Sprite();
                    roundRect.graphics.beginFill(0xFFFFFF);
                    roundRect.graphics.drawRoundRect(maskx,masky,maskw,maskh,rad);
                    roundRect.graphics.endFill();
                    menu.mask = roundRect;
            }
        }  
    }
}

任何人都可以帮助我解决我所缺少的内容...我不确定是否需要覆盖任何菜单类功能。

当我加载示例时:

addEventListener("menuShow", onMenuShow);

发生火灾,但当我单击 PopUpButton 显示菜单时, onMenuShow 函数不会被触发,并且常规菜单显示时没有圆角。

对此的任何帮助表示赞赏。

谢谢

So I have a PopupButton and when I click on the button I want the Menu that pops up to have rounded corners. How would I go about doing this?

UPDATE:
I found an update similar to what I want to do, it can be found on the following page:

http://blog.flexmonkeypatches.com/2007/10/08/flex-rounded-menues-using-masking/comment-page-1/

The only difference is that I'm showing the Menu with a PopUpButton. So far this is what I have for my custom Menu:

package {

    import flash.display.Sprite;

    import mx.controls.Menu;
    import mx.events.MenuEvent;

    public class MyMenu extends Menu {

        public function MyMenu() {
            super();
            addEventListener("menuShow", onMenuShow);
        }

        private function onMenuShow(e:MenuEvent):void {
            callLater(maskRoundedCorners,[e]);
        }


     private function maskRoundedCorners(e:MenuEvent):void {

                var menu:Menu = e.menu as Menu;
                menu.cacheAsBitmap=false;

                if (!menu.mask){
                    var maskx:uint = menu.x;
                    var masky:uint = menu.y;
                    var maskw:uint = menu.getExplicitOrMeasuredWidth();
                    var maskh:uint = menu.getExplicitOrMeasuredHeight();
                    var rad:int = menu.getStyle("cornerRadius") * 2;

                    var roundRect:Sprite = new Sprite();
                    roundRect.graphics.beginFill(0xFFFFFF);
                    roundRect.graphics.drawRoundRect(maskx,masky,maskw,maskh,rad);
                    roundRect.graphics.endFill();
                    menu.mask = roundRect;
            }
        }  
    }
}

Can anyone help me out with what I'm missing...I'm not sure if i need to override any of the Menu classes functions.

When I load my example the:

addEventListener("menuShow", onMenuShow);

gets fire but when i click the PopUpButton to show the menu the onMenuShow function is not being fired and the regular menu is being display with out the rounded corners.

Any help on this is appreciated.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦亦如幻 2024-08-11 14:54:50

终于明白了这一点。这是我想出的解决方案:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
        <![CDATA[
            import mx.controls.Menu;

            [Bindable]
            private var myMenu:Menu;

            private function popUpButtonInit():void {
                myMenu = new Menu();
                myMenu.dataProvider = arr;

            }

            private function menuOpenHandler():void {
                    var maskx:uint = myMenu.x; 
                    var masky:uint = myMenu.y - 1; 
                    var maskw:uint = myMenu.getExplicitOrMeasuredWidth(); 
                    var maskh:uint = myMenu.getExplicitOrMeasuredHeight(); 
                    var rad:int = myMenu.getStyle("cornerRadius");

                    var roundRect:Sprite = new Sprite();
                    roundRect.graphics.beginFill( 0xFFFFFF );
                    roundRect.graphics.drawRoundRect( maskx, masky, maskw, maskh, rad ); 
                    roundRect.graphics.endFill(); 
                    myMenu.mask = roundRect;

            }           


        ]]>
    </mx:Script>

    <mx:Style>
        Menu {
            corner-radius: 30;
        }
    </mx:Style>

    <mx:Array id="arr">
        <mx:Object label="Alert" />
        <mx:Object label="Button" />
        <mx:Object label="ButtonBar" />
        <mx:Object label="CheckBox" />
        <mx:Object label="ColorPicker" />
        <mx:Object label="ComboBox" />
    </mx:Array>

    <mx:PopUpButton width="78" height="25"  
                    initialize="popUpButtonInit();" 
                    popUp="{myMenu}" popUpGap="3" open="menuOpenHandler();" 
                    horizontalCenter="0" verticalCenter="0">
    </mx:PopUpButton>

</mx:Application>

如果您有更好的解决方案,请评论。

Finally figured this out. Here is the solution that I came up with:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
        <![CDATA[
            import mx.controls.Menu;

            [Bindable]
            private var myMenu:Menu;

            private function popUpButtonInit():void {
                myMenu = new Menu();
                myMenu.dataProvider = arr;

            }

            private function menuOpenHandler():void {
                    var maskx:uint = myMenu.x; 
                    var masky:uint = myMenu.y - 1; 
                    var maskw:uint = myMenu.getExplicitOrMeasuredWidth(); 
                    var maskh:uint = myMenu.getExplicitOrMeasuredHeight(); 
                    var rad:int = myMenu.getStyle("cornerRadius");

                    var roundRect:Sprite = new Sprite();
                    roundRect.graphics.beginFill( 0xFFFFFF );
                    roundRect.graphics.drawRoundRect( maskx, masky, maskw, maskh, rad ); 
                    roundRect.graphics.endFill(); 
                    myMenu.mask = roundRect;

            }           


        ]]>
    </mx:Script>

    <mx:Style>
        Menu {
            corner-radius: 30;
        }
    </mx:Style>

    <mx:Array id="arr">
        <mx:Object label="Alert" />
        <mx:Object label="Button" />
        <mx:Object label="ButtonBar" />
        <mx:Object label="CheckBox" />
        <mx:Object label="ColorPicker" />
        <mx:Object label="ComboBox" />
    </mx:Array>

    <mx:PopUpButton width="78" height="25"  
                    initialize="popUpButtonInit();" 
                    popUp="{myMenu}" popUpGap="3" open="menuOpenHandler();" 
                    horizontalCenter="0" verticalCenter="0">
    </mx:PopUpButton>

</mx:Application>

If you happen to have a better solution please comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文