I've tried to create a fare calculator, but when i click on the button nothing happens, i haven't used action script for a while and cant work out why its not working.
Any help appreciated.
Code:
//----------- NUMBERS ------------\\
on(release){
var str_mileage:String
var str_pricepm:Number
var str_firstmile:Number
var str_fare:Number
//----------- CALCULATE ------------\\
str_mileage = miles_txt.text;
str_pricepm = 1.50;
str_firstmile = 1.70;
str_fare = parseInt(str_mileage) * str_pricepm + str_firstmile
str_fare.toString();
fare_txt.text = String(str_fare)
}
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
toString() returns a string, it doesn't convert to a string (as you seem to be trying to use it there). add a trace() statement after you calculate str_fare to see what its value is:
Code:
trace(str_fare);
and instead of casting str_fare as a string, just try using the toString() method:
It might not be the code, i cant seem to get the button to work
does any one know any good tutorials that i can follow, because i cant seem to get it working.
i have uploaded my program, could anybody please code one button, and explain what I've been doing wrong.
Preferably one of the fare selection buttons, when one is clicked id like it to be selected so the rollover/down image is showing and so its status can be compared against the other.
Last edited by chris1990; Jul 2nd, 2010 at 10:43 PM.
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
in ActionScript 3, if you have a text input called mileageInput, a button called calculate, and a dynamic text field with the name fareOutput, you could use the following code:
Code:
const PRICE_PER_MILE:Number = 1.5; // Price per mile
const PRICE_FIRST_MILE:Number = 1.7; // First mile
calculate.addEventListener(MouseEvent.CLICK, calculateFare, false, 0, true);
function calculateFare(e:MouseEvent):void {
var mileage:Number = parseInt(mileageInput.text);
// Mileage = first mile + (rest of miles * price per mile)
var fare:Number = (mileage - 1) * PRICE_PER_MILE + PRICE_FIRST_MILE;
fareOutput.text = fare.toString();
}