Reputation: 87
I get the following error when I try run my code.
TypeError: Error #1010: A term is undefined and has no properties.
private function calculateFIX001Value(custfields:Array):Number
{
var result:Number = new Number;
var valueObj:Object;
try{
var markUp:Number = 0.01;
var projectValue:String = "";
var marketCategory:String = "";
for each (var custField:Object in custfields)
{
if (custField.fieldLabel == 'Segment Category')
marketCategory = custField.selectedValue[0];
if (custField.fieldLabel == 'Project Value (R)')
projectValue = custField.selectedValue[0].toString().replace("R","");
projectValue = projectValue.replace(",","");
projectValue = projectValue.replace(",","");
projectValue = projectValue.replace(",","");
}
switch (marketCategory)
{
case "23": //5% Markup for Building
markUp = new Number(5 / 100);
break;
case "24": //11% Markup for Civils
markUp = new Number(11 / 100);
break;
case "25": //2% Markup for Scaffolding
markUp = new Number(2 / 100);
break;
default:
break;
}
if ((projectValue != "" && projectValue != '0') && marketCategory != "")
{
var revenue:Number = new Number;
//if (!_model.myProfile.switchOpportunityInMillions)
// revenue = parseFloat(projectValue) * 1000000 * markUp;
//else
revenue = parseFloat(projectValue) * markUp;
valueObj = new Object;
valueObj.label = "Expected Revenue";
valueObj.value = revenue;
//result.push(valueObj);
result = revenue;
//rm.saveOpportunityValue(_currentOpportunity.id, revenue);
}
else
{
var errorObj:Object = new Object;
var errMsg:String = "";
if (projectValue == '' || projectValue == '0')
errMsg = "Project value not specified";
if (marketCategory == "")
{
if (errMsg != "")
errMsg += " or no Segment Category has been selected";
else
errMsg = "No Segment Category has been selected";
}
errorObj.label = 'Cannot calculate value.';
errorObj.value = errMsg + '.';
//result.push(errorObj);
result = 0;
}
} catch(e:Error) {
Alert.show(e.toString());
}
return result;
}
Upvotes: 1
Views: 139
Reputation: 14406
Here is an indirect answer to help you solve your problem: (as there are lots of things in your code that could potentially be null or undefined and cause this error)
You have almost all your code in a try/catch
, so your error isn't actually getting thrown, you're just tracing out the error that was caught.
Throw the error (either by removing the try/catch or throwing it manually in the catch block):
catch(e:Error) {
Alert.show(e.toString()); //instead of this, for debugging, do the line below:
Throw e; //this will throw the error, so you will get your stack trace and the line number of error
}
To get the line number of the error and see the stack trace, you need to be running in the debug player or your IDE (eg Flash or FlashBuilder).
Upvotes: 0
Reputation: 56452
TypeError: Error #1010 is also known as "Null Pointer Exception", meaning you trying to access a null object property.
If you look at the line the stack trace tells you, you might found the reason without much problem.
Upvotes: 2