【问题标题】:How to override flex component rendering?如何覆盖 flex 组件渲染?
【发布时间】:2013-06-22 10:06:46
【问题描述】:

我正在学习 flex,但我无法理解动作脚本覆盖的原理 - 分配自定义处理程序并调用该类的 super 不会产生与正常继承机制所怀疑的结果相同的结果。

例如 - 图表系列具有属性 ItemRenderer - 用鼠标指向会给出?继承的基类?就我而言 -

mx.charts.chartClasses.HLOCSeriesBase.itemRenderer

flex 帮助给出了这个:

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++ 程序员,我无法理解这里可能出现的问题 - 所有实例都在做基类会做的事情??

也许有某种关于继承的语言特定概念?

【问题讨论】:

  • 向我们展示您是如何使用渲染器的。
  • @Reboog711 你的意思是 MXML 属性分配?我更新了我的问题
  • 是的,我想这就是我的意思。通常在指定一个类时,您使用完全限定的路径名​​;但是,由于您没有收到可能不是问题的编译器错误。审查您的渲染器代码;我不清楚为什么您的 CycleColorRenderer 应该与 HLOCSeriesBase 显示不同。
  • @Reboog711 它只是空屏幕,但通过 updateDisplayList 函数,我可以自己渲染条形图而不会出现问题,因为这些项目的信息已正确提供。特别是一件事-我正在使用命令行工具进行编译-mxmlc,但是由于它递归地搜索和编译其他类,并且不会产生任何错误,因此我认为它也编译了继承的类
  • 我不认为你的渲染器类应该扩展HLOCSeriesBase。如果您查看CandleStickSeries 类,您会发现它使用的默认项渲染器实现是CandleStickItemRenderer。我认为你应该看看那个类,然后扩展和覆盖它的方法来自定义事物的外观。

标签: apache-flex charts


【解决方案1】:

如果没有指定项目渲染器,CandleStickSeries 类默认使用CandleStickItemRenderer 来显示每个图表项目(来自CandleStickSeries.initStyles() 方法):

csSeriesStyle.setStyle("itemRenderer", new ClassFactory(mx.charts.renderers.CandlestickItemRenderer));

因此,如果您希望为 CandleStickSeries 自定义项目的外观,最好的办法是让您的项目渲染器扩展 CandleStickItemRenderer 类,而不是 HLOCSeriesBase

【讨论】:

    猜你喜欢
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2018-06-29
    • 2017-12-11
    相关资源
    最近更新 更多