14 Replies Latest reply on Apr 17, 2007 2:53 PM by Greg Dove

# Where is the &quot;a&quot; coming from?

Cant figure out where the "a" is coming from. How can I get rid of it? Here is the code:

And here is the sample: http://home.comcast.net/~shane.swoboda/pro_calc2.html

--------------------------------------------------------

salary = "0";
profactor = "0";

increasepercent = "0";
proincpercent = "0";
prodolinc = "0";
prosalary = "0";

increasedollar = "0";
dolincpercent = "0";
annualincrease = "0";
dolsalary = "0";

daysLabel.autoSize = "left";
daysLabel.text = "";
//

function roundThatNumber(theNumber:Number,thePlaces:Number) :Number
{
var theKey:Number=Math.pow(10,thePlaces);
//trace(theKey);
theNumber*=theKey;
//trace(theNumber);
theNumber=Math.round(theNumber);
theNumber/=theKey
return theNumber;
}

function formatCurrency(value:Number):String
{
var cents:Number = Math.round(value*100);
var result:String = Math.floor(cents/100) + ".";
cents %= 100;
if (cents < 10) {
result += "";
}
result += String(cents);
return result;
}

_root.onEnterFrame = function() {
asalary = salary;
aincreasepercent = increasepercent;
aprofactor = Number(dayslabel.text)/(365);
proincpercent = Number(aincreasepercent)* Number(aprofactor);
aprodolinc = Number(asalary)* Number(proincpercent)/(100);
aprosalary = Number(asalary)+Number(aprodolinc);

dolincpercent = Number(increasedollar)/Number(asalary)*(100);
bannualincrease = Number(dolincpercent)/Number(aprofactor);
bdolsalary = Number(asalary)+Number(increasedollar);

prosalary = (formatCurrency(aprosalary));
dolsalary = (formatCurrency(bdolsalary));
profactor = (roundThatNumber(aprofactor,3))*(100);
prodolinc = (formatCurrency(aprodolinc));
annualincrease = (roundThatNumber(bannualincrease,1));

var loH:Object = new Object();
loH.change = function(eO:Object) {
hDate = eO.target.selectedDate;
d = new Date(2007, 3, 1);
daysSinceHire = Math.ceil((d.getTime() - hDate.getTime()) / (1000 * 60 * 60 * 24));
daysLabel.text = daysSinceHire;
};
var loE:Object = new Object();
loE.change = function(eO:Object) {
eDate = eO.target.selectedDate;
if (hDate) {
daysSinceHire = Math.ceil((eDate.getTime()-hDate.getTime())/(1000*60*60*24));
daysLabel.text = ""+daysSinceHire+"";
}
};
effdate.selectedDate = new Date(2007, 3, 1);
};
• ###### 1. Re: Where is the &quot;a&quot; coming from?
Start by making your numbers Numbers. At the very least remove the surrounding quotes...even better add typing:

salary = "0";
becomes
var salary:Number=0;
• ###### 2. Re: Where is the &quot;a&quot; coming from?
your 'a' might be coming from the middle of NaN somewhere, but I can't really tell sorry. Also I don't know what your frame rate is set to but I'm guessing it might be high. Either way, this is causing the iexplorer page to chug through 80% of my CPU, somethings awry.

I can't see something that corresponds to daysLabel as as textfield in your app unless I'm missing something. If its not there then aprofactor (which relies on it) and its dependent calculations may have hiccups which could be leading to the problem.
• ###### 3. Re: Where is the &quot;a&quot; coming from?
Nope, that didn't work. Anything else you might suggest?

Thanks,
Shane
• ###### 4. Re: Where is the &quot;a&quot; coming from?
Sorry - what didn't work? Is there a daysLabel textfield or not? I can't see the calcuation appearing (unless, like I said I'm missing something)

does the calculation : daysLabel.text = daysSinceHire
appear in a textfield anywhere?
• ###### 5. Re: Where is the &quot;a&quot; coming from?

My frame rate is 12fps AS 2.0

You can see my sample I posted here. Thanks!

http://home.comcast.net/~shane.swoboda/pro_calc2.html
• ###### 6. Re: Where is the &quot;a&quot; coming from?
Oops sorry, yes there is a dayslabel text field off the screen - I don't need it except to do the calculation so i pushed it off to the side.
• ###### 7. Re: Where is the &quot;a&quot; coming from?
try changing

aprofactor = Number(dayslabel.text)/(365);

to
aprofactor = Number(daysLabel.text)/(365);
• ###### 8. Re: Where is the &quot;a&quot; coming from?
I don't think this is causing the problem, but I'd get rid of the quotes here as well:

daysLabel.text = ""+daysSinceHire+"";

to

daysLabel.text = daysSinceHire;
• ###### 9. Where is the &quot;a&quot; coming from?
either way, make sure all your daysLabel reference are the same as your textfield name, including matching case. That just might fix it.
• ###### 10. Re: Where is the &quot;a&quot; coming from?
Good eye, but it's still showing the "a"

Would it help if you looked at the .fla?

if so I posted here:

http://home.comcast.net/~shane.swoboda/pro_calc.fla
• ###### 11. Where is the &quot;a&quot; coming from?
change line 15 to

daysLabel.text = "0";

No, that's not all there's more... hang on
• ###### 12. Where is the &quot;a&quot; coming from?
the line numbers below could be out by 1 as I had put in a trace action that I forgot to take out.
line 52
change from
daysLabel.text = "there have been "+daysSinceHire+" days since hire.";

to
daysLabel.text = daysSinceHire;

and make line 60
daysLabel.text = daysSinceHire;
as I said earlier

then it works
• ###### 13. Re: Where is the &quot;a&quot; coming from?
Thanks for hanging in there with me on that GWD. I appreciate it!!
• ###### 14. Re: Where is the &quot;a&quot; coming from?
You're welcome