TileList itemrenderer错误:标记为覆盖的方法必须覆盖另一个方法

时间:2011-08-05 14:39:07

标签: flex actionscript-3 flex3

    <mx:TileList id="tl" allowMultipleSelection="true">             
     <mx:itemRenderer>
       <mx:Component>                       
         <mx:VBox height="100%"width="100%" borderSides="borderStyle="solid">
           <mx:Text id="txt1" text="{getText(XML(data))}" selectable="{_selectable}" />
            <mx:Script>
        <![CDATA[
        import mx.controls.listClasses.IListItemRenderer;

            public override function  set data(obj:Object):void{
            //this override function works alright 
            }   

          private function getText(data:XML):String{
          // some logic inside this function. Works fine. 
          }


    override protected function drawSelectionIndicator(indicator:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint, itemRenderer:IListItemRenderer):void{
        //this function gives me compile error - "Method marked override must override another method"                          }


           ]]>
        </mx:Script>
        </mx:VBox>
      </mx:Component>
    </mx:itemRenderer>
    </mx:TileList>

现在我知道我可以创建另一个类并扩展tilelist并在那里覆盖这个方法,它会正常工作,因为它会在超类的范围内找到要重写的方法。但我实际上想在组件级内联(我不想创建另一个文件,每次我必须在tilelist,datagrid等中进行小修改)。

-------------------------- FULL CODE Prototype(函数逻辑未编写)---------

    <mx:VBox horizontalAlign="center" verticalAlign="middle"> 
    <mx:HorizontalList id="headerList" width="100%" columnCount="7" paddingBottom="0" selectable="false" columnWidth="98" rowHeight="40">
    <mx:dataProvider>
                        <mx:Array>
                        <mx:String>Sunday</mx:String>
                        <mx:String>Monday</mx:String>
                        <mx:String>Tuesday</mx:String>
                        <mx:String>Wednesday</mx:String>
                        <mx:String>Thursday</mx:String>
                        <mx:String>Friday</mx:String>
                        <mx:String>Saturday</mx:String>
                        </mx:Array>
      </mx:dataProvider>
 <mx:itemRenderer>
<mx:Component>
<mx:VBox backgroundAlpha="0.8" height="100%" width="100%" horizontalAlign="center" paddingTop="0" verticalAlign="middle" borderSides="bottom left right" borderStyle="solid">
                            <mx:Label text="{data}" fontWeight="bold"/>
                        </mx:VBox>
                    </mx:Component>
                </mx:itemRenderer>
                </mx:HorizontalList>
                <mx:TileList id="tl" allowMultipleSelection="true" mouseOver="tl.setStyle('backgroundColor','0xFFFFFF')" paddingTop="0" height="100%" width="100%" borderSides="none"  dataProvider="{IndividualData.w.s}" maxRows="4" maxColumns="7" columnCount="7" rowCount="4" rowHeight="110" columnWidth="98">                
                 <mx:Script>
                    <![CDATA[
                        import mx.controls.listClasses.IListItemRenderer;
                        protected override function drawSelectionIndicator(indicator:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint, itemRenderer:IListItemRenderer):void{
                           return;             
                       }
                   ]]>
                </mx:Script>
                 <mx:itemRenderer>
                    <mx:Component>                      
                        <mx:VBox height="100%" horizontalAlign="center" width="100%" borderSides=" top bottom left right" borderStyle="solid"
                            click="outerDocument.onItemClick(event,XML(data));onEdit()" doubleClickEnabled="true" doubleClick="onScheduleDetail(data.@date)"  
                            verticalAlign="middle" mouseOver="onMouseOver()" mouseOut="onMouseOut()"
                            backgroundColor="{_bgColor}">
                            <mx:Text id="txt1" text="{getText(XML(data))}" selectable="{_selectable}" />
                            <mx:Script>
                            <![CDATA[
                                import mx.controls.listClasses.IListItemRenderer;
                                import mx.core.UIComponent;
                                import com.smartLinx.utils.DateUtils;
                                import com.smartLinx.utils.Helper;
                                import com.smartLinx.utils.DateUtils;
                                import com.smartLinx.ScheduleOptimizer.components.ScheduleDetail;
                                import mx.managers.PopUpManager;
                                [Bindable] private var _bgAlpha:Number;
                                [Bindable] private var _selectable:Boolean;
                                [Bindable] private var _bgColor:uint;       
                                [Bindable] private var _pastDated:Boolean;      

                                /* override protected function drawSelectionIndicator(indicator:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint, itemRenderer:IListItemRenderer):void
                                {
                                      return;
                                }  */
                                private function getText(data:XML):String
                                    {
                                     //                                 }

                                   private function onMouseOver():void{
                                      }

                                   private function onMouseOut():void{

                                      }  

                                   private function onEdit():void{
                                   }   

                                    public override function  set data(obj:Object):void
                                    {

                                        super.data = obj;                                   
                                    }                                   

                                private function onScheduleDetail(work_date:String):void
                                {
                                }
                                ]]>
                            </mx:Script>
                        </mx:VBox>
                    </mx:Component>
                </mx:itemRenderer>

                </mx:TileList>
            </mx:VBox>  
        </mx:VBox>

1 个答案:

答案 0 :(得分:2)

试试这个:

<mx:TileList id="tl" allowMultipleSelection="true">             
        <mx:Script>
    <![CDATA[
    import mx.controls.listClasses.IListItemRenderer;
override protected function drawSelectionIndicator(indicator:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint, itemRenderer:IListItemRenderer):void{
    //this function gives me compile error - "Method marked override must override another method"                          }


       ]]>
    </mx:Script>
 <mx:itemRenderer>
   <mx:Component>                       
     <mx:VBox height="100%"width="100%" borderSides="borderStyle="solid">
       <mx:Text id="txt1" text="{getText(XML(data))}" selectable="{_selectable}" />
        <mx:Script>
    <![CDATA[
        public override function  set data(obj:Object):void{
        //this override function works alright 
        }   
       ]]>
    </mx:Script>
    </mx:VBox>
  </mx:Component>
</mx:itemRenderer>
</mx:TileList>

在你的情况下,你试图覆盖不存在的VBox方法。

扩展帖子后编辑:

我一直遵循的Flex规则#1是:

  

避免使用内联MXML组件。

内联组件会增加复杂性并降低可读性。它只能在快速原型设计的情况下使用(只需简单的标记而无需代码),当你肯定知道自己在做什么时。所以你需要丰富的实践技能。

但是您的代码至少有三种语言可以避免内联组件:

  1. 它有多个内联组件。
  2. 它具有内联组件的ActionScript代码。
  3. 整个MXML课程相当庞大且难以阅读。
  4. 所以我建议你做两件事:

    1. 摆脱当前代码中的内联组件。在单独的MXML类中提取组件。
    2. 不要再使用它们了。当你有足够的技能时,你可以明智地违反这条规则:)