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

发布于 2024-11-28 03:30:58 字数 6674 浏览 1 评论 0原文

    <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并重写该方法,它会正常工作,因为它会发现该方法在超类的范围内被重写。但我实际上想在组件级别内联执行此操作(我不想创建另一个文件,每次我必须在图块列表、数据网格等中进行小的修改)。

-------------------------- 完整代码原型(未编写功能逻辑)---------

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

Now I know I could make another class and extend tilelist and override this method there and it will work alright, because it will find the method to be overridden in super class's scope. But I actually want to do this inline at component level (I don't want to create another file, every time I have to do small modification in a tilelist, datagrid etc).

-------------------------- FULL CODE Prototype (with functions logic not written)---------

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

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

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

发布评论

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

评论(1

阳光下的泡沫是彩色的 2024-12-05 03:30:58

试试这个:

<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 类相当大且难以阅读。

所以我建议你做两件事:

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

Try this:

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

In your case you're trying to override VBox's method which is absent.

Edited after expanding post:

The Flex Rule #1 which I always follow is:

Avoid inline MXML components.

Inline components increase complexity and decrease readability. It can be used only in case of fast prototyping (just simple markup without code) when you definitely know what you're doing. So you need rich practical skills for that.

But your code has at least three simptoms to avoid inline components:

  1. It has more than one inline component.
  2. It has ActionScript code for inline components.
  3. The whole MXML class is rather big and complex to read.

So I suggest you two things:

  1. Get rid of inline components in your current code. Extract components in separate MXML classes.
  2. Do not use them anymore. When you'll have enough skills you can break this rule wisely :)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文