【原创】关于flexviewer中引入图表时报的TypeError #1009解决方法

本文针对自定义Widget中引入图表导致的TypeError#1009错误提供了解决方案。介绍了两种方法:一是通过添加copyStyleFromParent方法并调用预初始化处理函数;二是覆盖模块工厂方法,确保样式正确继承。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     在自定义的widget中引入图表后,运行时出现TypeError #1009错误。本人网上查找了很多资料,其中大部分都是关于Flash中的动画效果问题,与这里的问题关系型不太大。故把问题的解决方法写在这里,与人方便,与己方便。

     方法一:

     1.在自定义的widget中添加如下两个方法:

                      private function copyStyleFromParent(selector:String):void
                     {
                            var chartBaseStyle:CSSStyleDeclaration = styleManager.getStyleDeclaration(selector);
                            if (!chartBaseStyle && styleManager.parent)
                           {
                                   var parentStyle:CSSStyleDeclaration = styleManager.parent.getStyleDeclaration(selector);
                                   if (parentStyle)
                                  {
                                         styleManager.setStyleDeclaration(selector, parentStyle, false);
                                  }
                           }
                     }
 
                      protected function preinitializeHandler ():void
                     {
                            var styleObjects:Array =new Array();//FlexGlobals.topLevelApplication.styleManager.selectors;
                           styleObjects.push( "mx.charts.chartClasses.ChartBase" );
                            styleObjects.push( "mx.charts.chartClasses.CartesianChart" );
                            styleObjects.push( "mx.charts.chartClasses.PolarChart" );
                           styleObjects.push( "mx.charts.BarChart");
                           styleObjects.push( "mx.charts.ColumnChart" );
                           styleObjects.push( "mx.charts.LineChart");
                           styleObjects.push( "mx.charts.PieChart");
                           styleObjects.push( "mx.charts.AxisRenderer" );
                           styleObjects.push( ".blockCategoryAxis");
                           styleObjects.push( ".blockNumericAxis");
                           styleObjects.push( ".linedNumericAxis");
                           styleObjects.push( ".dashedNumericAxis");
                           styleObjects.push( ".dashedCategoryAxis");
                           styleObjects.push( ".hangingCategoryAxis");
                           styleObjects.push( "mx.charts.GridLines");
                           styleObjects.push( ".horizontalGridLines");
                           styleObjects.push( "mx.charts.series.BarSeries" );
                           styleObjects.push( "mx.charts.series.ColumnSeries" );
                           styleObjects.push( "mx.charts.series.LineSeries" );
                           styleObjects.push( "mx.charts.series.PieSeries" );
                           
                            for each(var styleObj:String in styleObjects) {
                             
                                  copyStyleFromParent(styleObj);
                           }
                     }
  2.在该自定义widget头部中添加preinitialize="preinitializeHandler ()" 。
      方法二:
      在自定义widget中覆盖父类的moduleFactory方法:
  override public function get moduleFactory():IFlexModuleFactory {
     return FlexGlobals.topLevelApplication.moduleFactory;
   }
  
  

转载于:https://www.cnblogs.com/javasharp/p/3764852.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值