TypeError: Error #1009: Cannot access a property or method of a null object reference comes from this part of codequeryTask.executeLastResult.attributesit does not matter where you use this codein ColumnChart tag<mx:ColumnChart id="columnChart"
dataProvider="{queryTask.executeLastResult.attributes}"
visible="{queryTask.executeLastResult != null}">
</mx:ColumnChart>
or in script tagfunction queryOnClick():void
{
/** execute your query, then add the following: */
columnChart.dataProvider = queryTask.executeLastResult.attributes;
if(queryTast.executeLastResult != null)
{
columnChart.visible = true;
}else{
columnChart.visible = false;
}
}
If the queryTask is never executed, then queryTask.executeLastResult is null!!! So queryTask.executeLastResult.attributes returns TypeError: Error #1009: Cannot access a property or method of a null object referenceexample / rulevar myAnyTypeObject:* = null;
var somePr:* = myAnyTypeObject.someproperty; // returns TypeError: Error #1009: Cannot access a property ...
myAnyTypeObject.executeSomeFunction();// returns TypeError: Error #1009: Cannot access ... method ...
Right?I would suggest to take Ben's code with some changesfunction queryOnClick():void
{
if(queryTask.executeLastResult != null)
{
columnChart.dataProvider = queryTask.executeLastResult.attributes;
columnChart.visible = true;
}else{
columnChart.visible = false;
}
}