TileList itemrenderer 错误:标记为重写的方法必须重写另一个方法
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
在您的情况下,您正在尝试覆盖
VBox
不存在的方法。扩展帖子后编辑:
我始终遵循的 Flex 规则#1 是:
内联组件增加了复杂性并降低了可读性。仅当您明确知道自己在做什么时,才可以在快速原型设计(只是没有代码的简单标记)的情况下使用它。所以你需要丰富的实践技能。
但是你的代码至少有三个避免内联组件的方法:
所以我建议你做两件事:
Try this:
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:
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:
So I suggest you two things: