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()[E:\dev\4.y\frameworks\proje cts\framework\src\mx\core\UIComponent.as:8219]
at mx.managers::LayoutManager/validateClient()[E:\dev\4.y\frameworks\pro jects\framework\src\mx\managers\LayoutManager.as:957]
at mx.managers::PopUpManagerImpl/addPopUp()
at mx.managers::PopUpManager$/addPopUp()
Thanks in Advance
Niranjan Swain
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.
The crash is occurring here in ChartBase.as
private function initStyles():Boolean
{
HaloDefaults.init(styleManager);
var chartBaseStyle:CSSStyleDeclaration = styleManager.getStyleDeclaration("mx.charts.chartClasses.ChartBase");
chartBaseStyle.setStyle("chartSeriesStyles", HaloDefaults.chartBaseChartSeriesStyles); <<<<<<<<<<< Occurs here. chartBaseStyle is null.
chartBaseStyle.setStyle("fill", new SolidColor(0xFFFFFF, 0));
chartBaseStyle.setStyle("calloutStroke", new SolidColorStroke(0x888888,2));
return true;
}
Ah ha! Caught me. I will be back in a few hours to post it, I just shut down my VM. I can tell you that instead of the two PopUpManager lines, I have two Layoutmanager lines.
Details in a few hours, though I know you might not respond until tomorrow. Thanks for being so avaiable to answer questions!
Trace:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.charts.chartClasses::ChartBase/initStyles()[E:\dev\4.y\frameworks\ projects\charts\src\mx\charts\chartClasses\ChartBase.as:1862]
at mx.charts.chartClasses::ChartBase/set moduleFactory()[E:\dev\4.y\frameworks\projects\charts\src\mx\charts\c hartClasses\ChartBase.as:1894]
at mx.charts.chartClasses::CartesianChart/set moduleFactory()[E:\dev\4.y\frameworks\projects\charts\src\mx\charts\c hartClasses\CartesianChart.as:816]
at mx.charts::LineChart/set moduleFactory()[E:\dev\4.y\frameworks\projects\charts\src\mx\charts\L ineChart.as:191]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Group.as: 1590]
at spark.components::Group/setMXMLContent()[E:\dev\4.y\frameworks\projec ts\spark\src\spark\components\Group.as:633]
at spark.components::Group/createChildren()[E:\dev\4.y\frameworks\projec ts\spark\src\spark\components\Group.as:855]
at mx.core::UIComponent/initialize()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7634]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as :7495]
at mx.core::UIComponent/addChildAt()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7199]
at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.y\fr ameworks\projects\spark\src\spark\components\Group.as:2037]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Group.as: 1628]
at spark.components::Group/addElementAt()[E:\dev\4.y\frameworks\projects \spark\src\spark\components\Group.as:1387]
at mx.states::AddItems/addItemsToContentHolder()[E:\dev\4.y\frameworks\p rojects\framework\src\mx\states\AddItems.as:782]
at mx.states::AddItems/apply()[E:\dev\4.y\frameworks\projects\framework\ src\mx\states\AddItems.as:563]
at mx.core::UIComponent/applyState()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:10741]
at mx.core::UIComponent/commitCurrentState()[E:\dev\4.y\frameworks\proje cts\framework\src\mx\core\UIComponent.as:10487]
at mx.core::UIComponent/commitProperties()[E:\dev\4.y\frameworks\project s\framework\src\mx\core\UIComponent.as:8304]
at spark.components.supportClasses::SkinnableComponent/commitProperties( )[E:\dev\4.y\frameworks\projects\spark\src\spark\components\supportCla sses\SkinnableComponent.as:452]
at spark.components::Application/commitProperties()[E:\dev\4.y\framework s\projects\spark\src\spark\components\Application.as:1532]
at mx.core::UIComponent/validateProperties()[E:\dev\4.y\frameworks\proje cts\framework\src\mx\core\UIComponent.as:8219]
at mx.managers::LayoutManager/validateProperties()[E:\dev\4.y\frameworks \projects\framework\src\mx\managers\LayoutManager.as:597]
at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\framewo rks\projects\framework\src\mx\managers\LayoutManager.as:783]
at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y \frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]
Okay, it has a few key differences. Thanks for calling me on that.
Okay, I have more details now.
I created a new application as requested and placed the SWFLoader link within and it worked. So I started playing around with our main application to try and find a setting that may have been conflicting.
I discovered something interesting. Within the main application we have 6 other LineCharts. Since that was the only thing I could find that was related, yet different from running the application in the Test Case, I tried commenting all our graphs out.
It ran successfully.
Does this help at all? I am going to keep poking around nd try to find why an internally run application with graphs would crash if the main application has graphs. The disturbing part, however, is that this all works fine in FlashBuilder 4.5.
This crashes, new test case.
{code}
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="200" minHeight="200"
xmlns:ns="library://ns.ntorus.com/common"
>
<s:layout>
<s:VerticalLayout paddingTop="8" paddingRight="12" paddingBottom="0" paddingLeft="12"/>
</s:layout>
<fx:Declarations>
</fx:Declarations>
<s:BorderContainer width="20" height="16" toolTip="Trend lines">
<mx:LineChart id="sparkGraph1" width="18" height="14">
<mx:seriesFilters>
<fx:Array/>
</mx:seriesFilters>
<mx:horizontalAxis>
<mx:CategoryAxis id="xAxis1" categoryField="Period"/>
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{xAxis1}"
minorTickPlacement="none"
tickPlacement="none"
labelGap="0"
showLabels="false"
showLine="false"/>
</mx:horizontalAxisRenderers>
<mx:verticalAxis>
<mx:LinearAxis id="yAxis1"/>
</mx:verticalAxis>
<mx:verticalAxisRenderers>
<mx:AxisRenderer axis="{yAxis1}"
minorTickPlacement="none"
tickPlacement="none"
labelGap="0"
showLabels="false"
showLine="false" />
</mx:verticalAxisRenderers>
<mx:series>
<mx:LineSeries yField="Data" stroke="{stroke1}">
<mx:lineStroke>
<mx:SolidColorStroke id="stroke1" color="#1a5b8b" weight="1"/>
</mx:lineStroke>
</mx:LineSeries>
</mx:series>
<mx:backgroundElements/>
</mx:LineChart>
</s:BorderContainer>
<ns:LoadingContainer id="loadingContainer" width="100%" height="100%">
<s:VGroup width="100%" height="100%" visible="true">
<s:Panel id="chartDisplay" height="200" width="100%" backgroundColor="#111111">
<mx:SWFLoader id="charts" source="Graphs.swf" height="100%" width="100%"/>
</s:Panel>
</s:VGroup>
</ns:LoadingContainer>
</s:Application>
{/code}
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.
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.loadi ngContainer.SkinnableContainerSkin23.contentGroup.VGroup25.chartDispla y.PanelSkin27._PanelSkin_Group1.contents.contentGroup.performanceChart s.FlexLoader36.instance49.Graphs42.ApplicationSkin43._ApplicationSkin_ Group1.contentGroup.VGroup46.HGroup47.ddlGraphChoice cannot be found.
at spark.components.supportClasses::SkinnableComponent/attachSkin()[E:\d ev\4.y\frameworks\projects\spark\src\spark\components\supportClasses\S kinnableComponent.as:698]
at spark.components.supportClasses::SkinnableComponent/validateSkinChang e()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\supportC lasses\SkinnableComponent.as:443]
at spark.components.supportClasses::SkinnableComponent/createChildren()[ E:\dev\4.y\frameworks\projects\spark\src\spark\components\supportClass es\SkinnableComponent.as:406]
at mx.core::UIComponent/initialize()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7634]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as :7495]
at mx.core::UIComponent/addChildAt()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7199]
at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.y\fr ameworks\projects\spark\src\spark\components\Group.as:2037]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Group.as: 1628]
at spark.components::Group/setMXMLContent()[E:\dev\4.y\frameworks\projec ts\spark\src\spark\components\Group.as:633]
at spark.components::Group/createChildren()[E:\dev\4.y\frameworks\projec ts\spark\src\spark\components\Group.as:855]
at mx.core::UIComponent/initialize()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7634]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as :7495]
at mx.core::UIComponent/addChildAt()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7199]
at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.y\fr ameworks\projects\spark\src\spark\components\Group.as:2037]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Group.as: 1628]
at spark.components::Group/setMXMLContent()[E:\dev\4.y\frameworks\projec ts\spark\src\spark\components\Group.as:633]
at spark.components::Group/createChildren()[E:\dev\4.y\frameworks\projec ts\spark\src\spark\components\Group.as:855]
at mx.core::UIComponent/initialize()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7634]
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as :7495]
at mx.core::UIComponent/addChildAt()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7199]
at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.y\fr ameworks\projects\spark\src\spark\components\Group.as:2037]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Group.as: 1628]
at spark.components::Group/setMXMLContent()[E:\dev\4.y\frameworks\projec ts\spark\src\spark\components\Group.as:633]
at spark.components::Group/set mxmlContent()[E:\dev\4.y\frameworks\projects\spark\src\spark\componen ts\Group.as:573]
at spark.components::SkinnableContainer/set mxmlContent()[E:\dev\4.y\frameworks\projects\spark\src\spark\componen ts\SkinnableContainer.as:657]
at spark.components::SkinnableContainer/createDeferredContent()[E:\dev\4 .y\frameworks\projects\spark\src\spark\components\SkinnableContainer.a s:1050]
at spark.components::SkinnableContainer/createContentIfNeeded()[E:\dev\4 .y\frameworks\projects\spark\src\spark\components\SkinnableContainer.a s:1078]
at spark.components::SkinnableContainer/createChildren()[E:\dev\4.y\fram eworks\projects\spark\src\spark\components\SkinnableContainer.as:885]
at spark.components::Application/createChildren()[E:\dev\4.y\frameworks\ projects\spark\src\spark\components\Application.as:1504]
at mx.core::UIComponent/initialize()[E:\dev\4.y\frameworks\projects\fram ework\src\mx\core\UIComponent.as:7634]
at spark.components::Application/initialize()[E:\dev\4.y\frameworks\proj ects\spark\src\spark\components\Application.as:1355]
at Graphs/initialize()
at mx.managers.systemClasses::ChildManager/childAdded()[E:\dev\4.y\frame works\projects\framework\src\mx\managers\systemClasses\ChildManager.as :189]
at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()[E: \dev\4.y\frameworks\projects\framework\src\mx\managers\systemClasses\C hildManager.as:359]
at mx.managers::SystemManager/initializeTopLevelWindow()[E:\dev\4.y\fram eworks\projects\framework\src\mx\managers\SystemManager.as:3057]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemMana ger.as:2843]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemMana ger.as:2723]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()[E:\dev\4.y\frameworks\project s\framework\src\mx\preloaders\Preloader.as:542]
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()[C:\SVN\Graphs.mxml:10]
at Graphs/get moduleFactory()[C:\SVN\Graphs.mxml:10]
at Graphs/get moduleFactory()[C:\SVN\Graphs.mxml:10]
at Graphs/get moduleFactory()[C:\SVN\Graphs.mxml:10]
at Graphs/get moduleFactory()[C:\SVN\Graphs.mxml:10]
at Graphs/get moduleFactory()[C:\SVN\Graphs.mxml:10]
at Graphs/get moduleFactory()[C:\SVN\Graphs.mxml:10]
at Graphs/get moduleFactory()[C:\SVN\Graphs.mxml:10]
.... and on forever.
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?
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);
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;
}
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(styl eObj);
styleManager.setStyleDeclaration(styleObj, style, true);
}
}
{/code}
This fixes the problem
override public function get moduleFactory():IFlexModuleFactory
{
return FlexGlobals.topLevelApplication.moduleFactory;
}
I don't see how this is going to work when you have e.g. a LineChart that wants to get it's styles in a Module. Do you want me to extend all LineChart classe and then add this function everywhere where the stylemanager is used?
Olivier
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
Luciano's solution worked for me. I mimicked his settings for RSL and debugging. I have not tested it in production, but these settings work for modular development. Note both the shell project and the modules project need these settings. The base library which actually contains the charting code is the rsl.
Muchas gracias Luiano.
North America
Europe, Middle East and Africa
Asia Pacific