我正在学习flex,但我无法理解动作脚本覆盖的哲学 - 分配自定义处理程序和调用该类的super不会产生与我从正常继承机制怀疑的结果相同的结果。
例如 - 图表系列具有属性ItemRenderer - 用鼠标指向给出了?继承的基类?在我的情况下 -
mx.charts.chartClasses.HLOCSeriesBase.itemRenderer
flex help给出了这个:
itemRenderer
Type: mx.core.IFactory CSS Inheritance: No
Language Version: ActionScript 3.0 Product Version: Flex 3 Runtime Versions: Flash9, AIR 1.1
A factory that represents the class the series will use to represent individual items on the chart. This class is instantiated once for each element in the chart. Classes used as an itemRenderer should implement the IFlexDisplayObject, ISimpleStyleClient, and IDataRenderer interfaces. The data property is assigned the chartItem that the skin instance renders.
所以我接着创造了一个继承它的类女士:
package { // Empty package.
import mx.charts.series.items.HLOCSeriesItem;
import mx.core.IDataRenderer;
import mx.core.IFlexDisplayObject;
import mx.styles.ISimpleStyleClient;
import flash.display.Graphics;
import mx.charts.chartClasses.HLOCSeriesBase;
import mx.charts.series.CandlestickSeries;
public class CycleColorRenderer extends HLOCSeriesBase
implements IFlexDisplayObject, ISimpleStyleClient, IDataRenderer {
private var _chartItem:HLOCSeriesItem;
public function CycleColorRenderer() {
super();
}
public function get data():Object {
return _chartItem;
}
public function set data(value:Object):void {
_chartItem = value as HLOCSeriesItem;
invalidateDisplayList();
}
override protected function
updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
}
MXML应用程序呈现重新分配:
<mx:CandlestickSeries
dataProvider="{TICKER}"
openField="open"
highField="high"
lowField="low"
closeField="close"
displayName="TICKER"
itemRenderer="CycleColorRenderer"
>
它编译好了,但运行它我看到一个空列表和C与一些C ++程序员我不知道这里可能出错 - 所有实例都在做基类会做什么??
也许有一些关于继承的语言特定概念?
答案 0 :(得分:2)
如果未指定项呈示器,则CandleStickSeries
类默认使用CandleStickItemRenderer
显示每个图表项(来自CandleStickSeries.initStyles()
方法):
csSeriesStyle.setStyle("itemRenderer", new ClassFactory(mx.charts.renderers.CandlestickItemRenderer));
因此,如果您希望为CandleStickSeries
自定义项目的外观,最好的办法是让您的项目渲染器扩展CandleStickItemRenderer
课程,而不是HLOCSeriesBase
。