I've tried another code and still get the error when I click the menu:

TypeError: Error #1034: Type Coercion failed: cannot convert
myrende...@47410a1 to mx.controls.menuClasses.IMenuItemRenderer.
        at 
mx.controls::Menu/http://www.adobe.com/2006/flex/mx/internal::deleteDependentSubMenus()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\controls\Menu.as:2275]
        at 
mx.controls::Menu/http://www.adobe.com/2006/flex/mx/internal::hideAllMenus()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\controls\Menu.as:2289]
        at 
mx.controls::Menu/mouseUpHandler()[C:\autobuild\3.5.0\frameworks\projects\framework\src\mx\controls\Menu.as:1706]

In my code I do implement all 5 methods listed at the
http://livedocs.adobe.com/flex/3/langref/mx/controls/menuClasses/IMenuItemRenderer.html
so I'm not sure, what is missing here?

MyRenderer.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml";
alpha="0.4" width="100%" height="100%">
        <mx:Script>
                <![CDATA[
                        import mx.events.*;
                        import mx.controls.*;

                        [Bindable]
                        private var color:uint;
                        
                        override public function set data(value:Object):void {
                                if(value != null) {
                                        super.data = value;
                                        lb.text = String(value.label);
                                        color = (lb.text.indexOf('♥') != -1 ||
                                                     lb.text.indexOf('♦') != 
-1) ? 0xFF0000 : 0x000000;
                                }
                                dispatchEvent(new 
FlexEvent(FlexEvent.DATA_CHANGE));
                        }
                        
                        // Internal variable for the property value.
                        private var _menu:Menu;
                        
                        public function get menu():Menu {
                                return _menu;
                        }
                        
                        public function set menu(value:Menu):void {
                                _menu = value;
                        }
                                                
                        public function get measuredBranchIconWidth():Number { 
return 50;}
                        public function get measuredTypeIconWidth ():Number { 
return 50;}
                        public function get measuredIconWidth ():Number { 
return 50;}

                ]]>
        </mx:Script>
        <mx:Label id="lb" color="{color}" />
</mx:Canvas>


Test.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; creationPolicy="all">
        <mx:Style>
                @font-face {
                        src:url("C:\\WINDOWS\\Fonts\\times.ttf");
                        fontFamily: myFont;
                        /* card suits */
                        unicodeRange: U+2660-U+266B;
                }
                Menu, Label {
                        fontFamily: myFont;
                        fontSize: 24;
                }
        </mx:Style>
        
        <mx:Script>
                <![CDATA[
                        import mx.controls.*;

                        private function createMenu():void {
                                var bids:Array = [{label: "Pass"}];
                                for (var i:uint = 7; i <= 10; i++)
                                        for (var j:uint = 0; j < 4; j++)
                                                bids.unshift({label: 
i+"♠♣♦♥".charAt(j%4)});
                                
                                var menu:Menu = new Menu();
                                menu.dataProvider = bids;
                                menu.itemRenderer = new 
ClassFactory(MyRenderer);
                                menu.selectedIndex = 0;
                                pub.popUp = menu;
                        }
                        
                ]]>
        </mx:Script>
        
        <mx:Canvas width="100%" height="100%">
        </mx:Canvas>
        
        <mx:ApplicationControlBar width="100%">
                <mx:Spacer width="100%"/>
                <mx:PopUpButton id="pub" creationComplete="createMenu();"/>
        </mx:ApplicationControlBar>
</mx:Application>

Reply via email to