Results 1 to 4 of 4

Thread: [FLASH8] AS code for a "Return or Enter" keystoke; how?

  1. #1
    Join Date
    Aug 2005
    Location
    Dorset, England
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default [FLASH8] AS code for a "Return or Enter" keystoke; how?

    I had no luck on another forum (Flash) with this, and suddenly realised I should have posted here first anyway...

    I'm creating a simple memory test, and the user is to memorise the words on screen for a few seconds and then input their answer on the next frame.

    http://i52.photobucket.com/albums/g2...elp/input1.jpg

    1st screen fades away and then 2nd screen comes up where the user is to input the memorised text into a 'dynamic', multiline with wrap textbox and click submit.

    http://i52.photobucket.com/albums/g2...elp/input2.jpg

    However, when user clicks submit they get the cross symbol to show a wrong answer even when they've inputted correctly.

    http://i52.photobucket.com/albums/g2...elp/input3.jpg

    I suspect when the user presses 'return' or 'enter', whilst typing their answer, that key stroke is not accounted for in my answer within the AS code .text == "Blue Chair Two".

    This code works fine when the text box is single line.

    So, how would I rectify this?

    This is my code

    PHP Code:

    tick_mc
    ._x 244.4;
    tick_mc._y 128.4;
    tick_mc._visible false;
    cross_mc._x 244.4;
    cross_mc._y 128.4;
    cross_mc._visible false;
    //
    stop();
    //
    submit_btn.onRelease = function() {
     if (
    wordinput1_txt.text == "Blue Chair Two") {
      
    tick_mc._visible true;
      
    cross_mc._visible false;
     }else{
      
    cross_mc._visible true;
     }
    }; 
    Thanks
    Last edited by FordCorsair; 11-11-2008 at 03:15 PM. Reason: fixing image links

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Depends on what has focus when they press enter. You can tell by adding this:

    Code:
    TextField.prototype.onKeyDown = function () {
      if (Key.getCode() == Key.ENTER) {
        // Enter was pressed.
      }
    };
    It can get tricky, some keys are reserved by Flash (such as enter) for other purposes. You can disable/get around/ use them another way, but it can be complicated. For one way, and one likely to help you or at least spark an idea can be found right here
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. The Following User Says Thank You to BLiZZaRD For This Useful Post:

    FordCorsair (11-11-2008)

  4. #3
    Join Date
    Aug 2005
    Location
    Dorset, England
    Posts
    46
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks BLiZZaRD, but for the past few days I've struggled to understand and get my head around the link you posted but I will continue to keep trying.

    However, through trial and error I've come about another way of doing my 'three' items list (multiline) input field (I used 3 separate single line input boxes) and then all to be checked by the submit button whether they're correct or not. I just happened to try '&&' in my code to see what it would do...

    Code:
    tick_mc._x = 274.5;
    tick_mc._y = 142.5;
    tick_mc._visible = false;
    cross_mc._x = 274.5;
    cross_mc._y = 142.5;
    cross_mc._visible = false;
    //
    stop();
    //
    submit_btn.onRelease = function() {
    	if
    	(wordinput1_txt.text == "Blue" && wordinput2_txt.text == "Chair" && wordinput3_txt.text == "Two")
    	{
    		tick_mc._visible = true;
    		cross_mc._visible = false;
    	}else{
    		tick_mc._visible = false;
    		cross_mc._visible = true;
    	}
    
    };
    It may seem bit of a fudge but it works... and will do for now.

  5. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    ForCorsair, for something that simple, I would recommend the option that you chose. But, if this is part of a larger, more complicated whole, you might want to look into regular expressions in AS.

Bookmarks

Posting Permissions

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