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
Printable View
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
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 :)
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!
ok...I see
it is referring to the shift + 3 key, right?
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
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
Hooray! it worked in both versions!
you really made my day
thank you!
HAve a wonderful day!
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!
um, are you trying this inside Flash, when hitting CTRL+ENTER? If so, then try clicking on Control->Disable Keyboard Shortcuts
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.
oh, I see what you mean. Could you post your FLA file, 'cause I'll need to see your structure :)?
Gladly, but I need to find that button to attach a file... where is it?
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
BTW I am using AS2
it was because we were replacing the whole textfield's content with just that one sentence. Just add a + before =, like this:
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:Code:myMessage.text += "Sarah says:";
Actionscript Code:Selection.setFocus(myMessage);
Selection.setSelection(myMessage.text.length, myMessage.text.length);
Hope this helps :)