A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: flash converter not working :(

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    2

    flash converter not working :(

    Hi guys

    I am really stuck with this assignment i am supposed to hand in tomarrow ! so would appreciate any help.

    I have been told to make a simple converter using as3 in flash to convert kilometers to miles, even though I am kinda sure my code is correct, when i test the movie, type a random number and press enter, nothing happens

    here is the code:
    kilometers_txt.addEventListener(KeyboardEvent.KEY_ DOWN,convertKilometers);
    function convertKilometers(k:KeyboardEvent)void:{
    var kilometers:Number;
    var miles:Number;
    {
    if (k.keyCode==Keyboard.ENTER) {
    kilometers=Number(km_txt.text);
    miles=kilometers / 1.61;
    miles_txt.text=String(miles);


    }
    }
    I really reallly would appreciate any help. p.s i can even send u the .flv file
    thank you

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    2 errors (organized by colors):

    Code:
    kilometers_txt.addEventListener(KeyboardEvent.KEY_ DOWN,convertKilometers);
    function convertKilometers(k:KeyboardEvent)void:{ 
    	var kilometers:Number;
    	var miles:Number;
    	{
    	if (k.keyCode==Keyboard.ENTER) {
    		kilometers=Number(km_txt.text);
    		miles=kilometers / 1.61;
    		miles_txt.text=String(miles);
    	}
    }
    RED: What is that unnecessary bracket doing there? Remove it, lol

    GREEN: It's the other way, :void

    Also, instead of adding an Event Listener to your textfield, you can just add it to the stage:

    Actionscript Code:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, convertKilometers);

    Just saying

    Hope this helps, though, and also that I'm not too late
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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

HTML5 Development Center