Results 1 to 8 of 8

Thread: Flash 8.0 (ActionScript) - Code not working

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    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)
    	}
    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.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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:

    Code:
    trace(str_fare);
    and instead of casting str_fare as a string, just try using the toString() method:

    Code:
    fare_txt.text = str_fare.toString();

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    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.
    Attached Files Attached Files
    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.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Flash 8.0 (ActionScript) - Code not working

    i forgot to mention that i upgraded to cs3, i remade the file above in cs3
    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.

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Flash 8.0 (ActionScript) - Code not working

    did you create an AS2 or AS3 Flash file when you created it?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Flash 8.0 (ActionScript) - Code not working

    wen i started usin cs3 i started again an picked as3 document
    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.

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width