dkilby
asked on
FLEX + Calling Function From Main MXML
I have a MXML Component and want to call a function inside it from the main MXML but i am getting the follow error:
Error #1009: Cannot access a property or method of a null object reference.
the error is from the is line of code (see full code attached)
app.populateUtilization();
Error #1009: Cannot access a property or method of a null object reference.
the error is from the is line of code (see full code attached)
app.populateUtilization();
inside main MXML file
import components.Utilization;
private var app:Utilization;
private function init(evt:Event):void {
/* Set up full screen handler. */
Application.application.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
var myDate:Date = new Date();
var reportDate:Date = new Date(myDate.getTime() + (-1 * millisecondsPerDay));
var newdate:String = dateFormatter.format(reportDate);
dtReport.text = newdate;
}
private function fullScreenHandler(evt:FullScreenEvent):void {
if (evt.fullScreen) {
btnFull.label = "Normal";
} else {
btnFull.label = "Fullscreen";
app.populateUtilization();
}
}
inside the component file here is the function
public function populateUtilization():void
{
var service:WebService = new WebService();
service.addEventListener(ResultEvent.RESULT, utilizationResultHandler);
service.addEventListener(FaultEvent.FAULT, serviceFaultHandler);
service.loadWSDL("http://localhost/Operations/Operations.asmx?wsdl");
service.getUtilization(mainapp.dtReport.text);
}
ASKER
where should the instantiation line go? just before when i call the function? Is there a way i can make sure the component is loaded before calling it? or loading it somewhere so when the function is called i know it was called correctly?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i see app declared:
private var app:Utilization;
and i see the method call:
app.populateUtilization();
but i don't see it instantiated anywhere?
shouldn't there be a app = new Utilization() or something similar somewhere?