Flash 8.0 (ActionScript) - Code not working
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)
}
Re: Flash 8.0 (ActionScript) - Code not working
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:
and instead of casting str_fare as a string, just try using the toString() method:
Code:
fare_txt.text = str_fare.toString();
1 Attachment(s)
Re: Flash 8.0 (ActionScript) - Code not working
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.
Re: Flash 8.0 (ActionScript) - Code not working
I only play with ActionScript 3; I'm not familiar with older versions' way of handling events.
Re: Flash 8.0 (ActionScript) - Code not working
i forgot to mention that i upgraded to cs3, i remade the file above in cs3
Re: Flash 8.0 (ActionScript) - Code not working
did you create an AS2 or AS3 Flash file when you created it?
Re: Flash 8.0 (ActionScript) - Code not working
wen i started usin cs3 i started again an picked as3 document
Re: Flash 8.0 (ActionScript) - Code not working
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();
}