A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: creating input text shortcuts

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14

    creating input text shortcuts

    Hi everyone!

    is there a way to create text shortcuts for input text?

    ie

    is it possible to create a hot key in a input text swf

    eg, when I hit cntrl + 3 the swf file generates the word " Sarah says:"

    any constructive feedback much appreciated

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    You'll need to apply a listener:

    Actionscript Code:
    keyListener = new Object();
    keyListener.onKeyDown = function(){
        if(Key.isDown(Key.CONTROL)){
            if(Key.isDown(51)){
                txt.text = "Sarah says:";
            }
        }
    }
    Key.addListener(keyListener);

    the keylistener object listens for when a key is pressed, any key, but we check if CTRL is being pressed, and then if 3 is being pressed down in Key Code (CLICK HERE FOR LIST OF ALL KEY CODES, the digits on the RIGHT-side), and then execute the desired codes

    Hope this helps
    I am back, guys ... and finally 18 :P

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

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    Thank you so much!
    I immediatly tried it and realised I didn't understand what

    the "51"

    in "if(Key.isDown(51)){"

    means. Is it referring to a key? or is that where i should place my desired hot key?

    I will now look at the link for list of key codes you sent for clues.

    Thank you again! I will keep you posted!

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    ok...I see

    it is referring to the shift + 3 key, right?

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    Hmmm... what do I assign the listener too?

    after some fiddling about, I must say, I'm not sure where to put the as code ... I assumed it was the main timeline... but now I am not sure.

    also, is the text box supposed to have an instance name?

    does this apply for mac snow leopard also? flash cs5 ,as3

    I am still googling for more options
    your

  6. #6
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    oh, that was targeted for AS2 :P

    new code on Frame Actions [AS3]:

    Actionscript Code:
    import flash.events.Event;
    import flash.events.KeyboardEvent;

    var keyOne:Boolean = false;
    var keyTwo:Boolean = false;

    function keyFunction1(e:KeyboardEvent){
        if(e.keyCode == 17){
            keyOne = true;
        }
        if(keyOne == true && keyTwo == true){
            doSomething();
        }
    }

    function keyFunction2(e:KeyboardEvent){
        if(e.keyCode == 51){
            keyTwo = true;
        }
        if(keyOne == true && keyTwo == true){
            doSomething();
        }
    }

    function resetVars(e:KeyboardEvent){
        keyOne = false;
        keyTwo = false;
    }

    function doSomething(){
        txt.text = "Sarah says:";
    }

    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyFunction1);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyFunction2);
    stage.addEventListener(KeyboardEvent.KEY_UP, resetVars);

    yes, you'll need to give your textfield an instance name, and in this case, it'd be txt

    I know the code is WAY bigger than AS2, which is why I love AS2 more and hate AS3, lol :P
    I am back, guys ... and finally 18 :P

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

  7. #7
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    Hooray! it worked in both versions!
    you really made my day
    thank you!
    HAve a wonderful day!

  8. #8
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    Oh dear!
    I hate to be a pain... but every time I hit cmd + 3
    the swf does not only execute the text "sarah sais"

    but it also deletes all the other text below it and returns to line 1, the top of the page.

    I'm making this template for a live translation of a chat.. so I'm back at square 1 for now... I'll keep googling for Godot, but if you have the time, energy and feel like helping me...

    I'll be sooo greatful!

  9. #9
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    um, are you trying this inside Flash, when hitting CTRL+ENTER? If so, then try clicking on Control->Disable Keyboard Shortcuts
    I am back, guys ... and finally 18 :P

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

  10. #10
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    Yes, I did that but it deletes all the other text and returns to the first line with " Sarah says"

    I would like to stay on the line I am on , but insert the same thing " sarah" says" and then keep typing.

  11. #11
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    oh, I see what you mean. Could you post your FLA file, 'cause I'll need to see your structure ?
    I am back, guys ... and finally 18 :P

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

  12. #12
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    Gladly, but I need to find that button to attach a file... where is it?

  13. #13
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    OK.... there should be a zip file below.

    The sender02.swf sends text to the reciever.swf
    the the swf, I wanted to assign shortcuts in is sender02.swf

    It's a Dialogue between Sarah and her client , so as the person is typing the conversation, they need to have shortcuts like "Sarah said:"... then type the text below and "Client said:" then type the text below... however, every time I assign the short cut it all dissapears ans goes to line 1
    Attached Files Attached Files

  14. #14
    Junior Member
    Join Date
    Jan 2012
    Location
    Berlin
    Posts
    14
    BTW I am using AS2

  15. #15
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    it was because we were replacing the whole textfield's content with just that one sentence. Just add a + before =, like this:

    Code:
    myMessage.text += "Sarah says:";
    and it should work, but if you want the caret (text selection cursor/pointer) to be aligned AFTER the inserted text, use this after the above code in the keyListener:

    Actionscript Code:
    Selection.setFocus(myMessage);
    Selection.setSelection(myMessage.text.length, myMessage.text.length);

    Hope this helps
    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