Skip to main content
Participant
December 27, 2011
Question

Flex 4.6 unable load module, if it contains a chart component.

  • December 27, 2011
  • 7 replies
  • 15500 views

Hi All,

I am facing a problem in 4.6 flex SDK however it is working fine in earlier version sdks.

I used a column chart in a module and tried to load the module in flex 4.6 Application . It gives the following error.

12/27/2011-18:17:29.625-[ FATAL ] 1009 - Error #1009: Cannot access a property or method of a null object reference.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at mx.charts.chartClasses::ChartBase/initStyles()

at mx.charts.chartClasses::ChartBase/set moduleFactory()

at mx.charts.chartClasses::CartesianChart/set moduleFactory()

at mx.charts::ColumnChart/set moduleFactory()

at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()

at spark.components::Group/setMXMLContent()

at spark.components::Group/set mxmlContent()

at spark.components::SkinnableContainer/set mxmlContent()

at spark.components::SkinnableContainer/createDeferredContent()

at mx.containers::ViewStack/instantiateSelectedChild()

at mx.containers::ViewStack/commitProperties()

at mx.core::UIComponent/validateProperties()

at mx.managers::LayoutManager/validateClient()

at mx.managers::PopUpManagerImpl/addPopUp()

at mx.managers::PopUpManager$/addPopUp()

Thanks in Advance

Niranjan Swain

    This topic has been closed for replies.

    7 replies

    May 4, 2012

    A way to solve this is to manually update all styles from your root stylemanager to your module stylemanager.

    In de module main mxml class you add when you have a LineChart in your module:

    {code}

    <?xml version="1.0" encoding="utf-8"?>

    <s:Module xmlns:fx="http://ns.adobe.com/mxml/2009"

                          xmlns:s="library://ns.adobe.com/flex/spark"

                          xmlns:mx="library://ns.adobe.com/flex/mx"

                          width="100%" height="100%" preinitialize="preinitializeHandler(event)"

                          xmlns:swiz="http://swiz.swizframework.org">

    <fx:Script>

                        <![CDATA[

                                  import mx.core.FlexGlobals;

                                  import mx.events.FlexEvent;

                                  protected function preinitializeHandler(event:FlexEvent):void

                                  {

                                            var styleObjects:Array = FlexGlobals.topLevelApplication.styleManager.selectors;

                                            for each(var styleObj:String in styleObjects)  {

                                                      var style:CSSStyleDeclaration = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration(styleObj);

                                                      styleManager.setStyleDeclaration(styleObj, style, true);

                                            }

                                  }

    {/code}

    This fixes the problem

    Participant
    June 14, 2012

    I have a widget with a chart embedded in another widget. Worked fine under 4.1 SDK; crashes with

    TypeError: Error #1009: Cannot access a property or method of a null object reference.

           at mx.charts.chartClasses::ChartBase/initStyles()

    under 4.6. Adding odejonge's preinitialization to the widget with the chart fixed the problem.

    {code}

    <s:HGroup width="100%" height="100%"

              includeInLayout="{columnChartList.length > 0 ? true : false}"

              visible="{columnChartList.length > 0 ? true : false}">

              <mx:ColumnChart id="myChart"

            width="95%" height="150"

            dataProvider="{columnChartList}">

            <mx:horizontalAxis>

                <mx:CategoryAxis categoryField="namefield"/>

            </mx:horizontalAxis>

            <mx:series>

                <mx:ColumnSeries displayName="field" xField="namefield" yField="field"/>

            </mx:series>

        </mx:ColumnChart>

    </s:HGroup>

    {/code}

    Thanks, Olivier!

    Mike

    Participant
    July 2, 2012

    Need some help. I can't get any of the solutions to work?? Thanks!

    Participant
    April 27, 2012

    hi,I find a solution:

    as flowing:

    in the main mxml file, add a chart object  which type you used in the module file

    for example:

    private var _PieChart : PieChart = new  PieChart();

    then the application work correct.

    hope to help.

    January 16, 2012

    I forget to mention that you have to add that code into the module.mxml file.

    MyModule.xml

    override public function get moduleFactory():IFlexModuleFactory

    {

        return FlexGlobals.topLevelApplication.moduleFactory;

    }

    And on your "shell" app  (wich load modules) try this.

    Some place on your ShellApplication.mxml

    var minfo:IModuleInfo = ModuleManager.getModule(url_path);

    minfo.load(target, null, null, FlexGlobals.topLevelApplication.moduleFactory);

    Participant
    February 15, 2012

    I had similar problem. A module that uses Charts cannot load the styles.

    The solution was to create a Class that has a property of the type of each Chart that is used. And create an instance of this class in the main "shell" app.

    In my case we only used PieChart and ColumnChart, so I just needed to add two properties.

    import mx.charts.ColumnChart;
    import mx.charts.PieChart;

    class MxComponents
    {
    private var varChartsOne:PieChart;
    private var varChartsTwo:ColumnChart;
    }

    
    Participant
    March 29, 2012

    Hi guys,

    we are facing the same problem with charting components in a module application. we try to apply all your tips, but no rules!!! When using @charlieSkin solution we are able to load the module, but Parsley instantiation in module fails.

    Thanks in advance.

    January 16, 2012

    We'll I don't know how to explain this.

    Please share with me your test case project and I'll try to find a solution.

    The 4.6 SDK seems to be a unestable.

    Participating Frequently
    January 16, 2012

    4 posts up is my test case.  The only difference is that I added this code to my external swf:

    override public function get moduleFactory():IFlexModuleFactory

    {

        return FlexGlobals.topLevelApplication.moduleFactory;

    }

    I cannot post the external swf code.

    Summary of issue so far:

    - When you have a flex project with ChartBase elements and attempt to imbed by SWFLoader another flex project with ChartBase elements, the imbedded swf will fail in a null exception when attempting to load the ChartBase styles.

    - This was not an issue in Flex 4.5

    - Removing all ChartBase elements from the host application allows the imbedded application to work perfectly.  Removing the imbedded application allows the host application to run perfectly.   They just can't run together.

    Is there any chance that ChartBase itself is retaining some static reference to the first application that uses it, rendering the second inoperable?

    January 13, 2012

    Actually is working for me.

    My module proyect configuration

    Participating Frequently
    January 16, 2012

    Okay, back from a nice weekend!

    Any resolution yet?  While it looks like your office had some fun with the issue, I don't see a working solution for this 'unintended feature' of Flex 4.6.  Your project configuration really doesn't help me =)

    January 13, 2012

    We realize that overriding the get moduleFactory method. Works.

    /**  override this method on your module loaded byt the main app **/

    override public function get moduleFactory():IFlexModuleFactory {

                                            return FlexGlobals.topLevelApplication.moduleFactory;

    }

    Becasue this line of code (  var chartBaseStyle:CSSStyleDeclaration = styleManager.getStyleDeclaration("mx.charts.chartClasses.ChartBase");  ) is not able to find the rigth styleManager inherited styles.

    Participating Frequently
    January 13, 2012

    Okay, have two errors for you.  Note that we run this app as both an internal and external app.

    First error, as an internal swf using SWFLoader.

    Error: Skin for GraphTest.ApplicationSkin2._ApplicationSkin_Group1.contentGroup.loadingContainer.SkinnableContainerSkin23.contentGroup.VGroup25.chartDisplay.PanelSkin27._PanelSkin_Group1.contents.contentGroup.performanceCharts.FlexLoader36.instance49.Graphs42.ApplicationSkin43._ApplicationSkin_Group1.contentGroup.VGroup46.HGroup47.ddlGraphChoice cannot be found.

              at spark.components.supportClasses::SkinnableComponent/attachSkin()

              at spark.components.supportClasses::SkinnableComponent/validateSkinChange()

              at spark.components.supportClasses::SkinnableComponent/createChildren()

              at mx.core::UIComponent/initialize()

              at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()

              at mx.core::UIComponent/addChildAt()

              at spark.components::Group/addDisplayObjectToDisplayList()

              at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()

              at spark.components::Group/setMXMLContent()

              at spark.components::Group/createChildren()

              at mx.core::UIComponent/initialize()

              at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()

              at mx.core::UIComponent/addChildAt()

              at spark.components::Group/addDisplayObjectToDisplayList()

              at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()

              at spark.components::Group/setMXMLContent()

              at spark.components::Group/createChildren()

              at mx.core::UIComponent/initialize()

              at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()

              at mx.core::UIComponent/addChildAt()

              at spark.components::Group/addDisplayObjectToDisplayList()

              at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()

              at spark.components::Group/setMXMLContent()

              at spark.components::Group/set mxmlContent()

              at spark.components::SkinnableContainer/set mxmlContent()

              at spark.components::SkinnableContainer/createDeferredContent()

              at spark.components::SkinnableContainer/createContentIfNeeded()

              at spark.components::SkinnableContainer/createChildren()

              at spark.components::Application/createChildren()

              at mx.core::UIComponent/initialize()

              at spark.components::Application/initialize()

              at Graphs/initialize()

              at mx.managers.systemClasses::ChildManager/childAdded()

              at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()

              at mx.managers::SystemManager/initializeTopLevelWindow()

              at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()

              at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()

              at flash.events::EventDispatcher/dispatchEventFunction()

              at flash.events::EventDispatcher/dispatchEvent()

              at mx.preloaders::Preloader/timerHandler()

              at flash.utils::Timer/_timerDispatch()

              at flash.utils::Timer/tick()

    ~~~~~~

    And second error is an infinite loop when running the application on its own.  This is using the override you gave me.

    Error: Error #1023: Stack overflow occurred.

              at Graphs/get moduleFactory()

              at Graphs/get moduleFactory()

              at Graphs/get moduleFactory()

      at Graphs/get moduleFactory()

      at Graphs/get moduleFactory()

      at Graphs/get moduleFactory()

      at Graphs/get moduleFactory()

      at Graphs/get moduleFactory()

    .... and on forever.

    Participant
    December 27, 2011

    Could you post the code here, something to do with the casting of the module that is loaded.

    Participating Frequently
    January 11, 2012

    I am also experiencing this same error after upgrading to FlashBuilder 4.6.

    When I run the .swf as a separate application, it works just fine  When I embed it within another swf application, that is when the error occurs.  Here is the code which, when commented out, removes the error.  No failure in the swf itself, just in the SWFLoader.






    <s:Panel styleName="grayBack" id="chartDisplay" height="200" width="100%" backgroundColor="#ffffff">













    <mx:SWFLoader id="graphs" source="graphs.swf" height="100%" width="100%"/>






    <s:Button id="popoutButton" click="PopoutGraph(event)" right="3" top="3" toolTip="Expand Graphs"/>












    </s:Panel>

    Not sure how this will post, there is no 'code' tag selectable.

    Adobe Employee
    January 11, 2012

    What stack trace are you getting? You may have to use the module’s moduleFactory in the params to PopUpManager APIs.