-1

I'm creating a large "movie" using flash professional CC and AS3. In one scene I want my character to be IMing his friend. The scene is already animated and shows the back of his head and the viewer can read his screen.

I want the user to be able to type for my character, so whatever the user types shows up in the bottom of the chat box, and then when the user presses enter the same text appears in a different place on the screen.

Unfortunately I haven't even gotten CLOSE to making that happen. So far I'm stuck on getting the text from the input box to appear in a dynamic textbox elsewhere, so I've been watching tons of tutorials. This code runs without errors but does not output the text like I want.

var outputString = outputBox.text; //get key presses only when textfield is edited
    inputBox.addEventListener(KeyboardEvent.KEY_DOWN, handler);

function handler(event:KeyboardEvent) { //13 is enter key

function handler(event:KeyboardEvent) { //13 is enter key
if(event.charCode == 13) {  
    outputBox.text = "UserName: " + outputString;

}

}

(Please ignore the bad indentation, that's more of an issue with me not understanding how to paste code here haha.)

Anyways does anyone know what's wrong? I have been trying to figure this out for days so if anyone could share some example code for how to get what I described working properly it would be immensely appreciated. All I really need to be able to do is save the user input so I can display it whererever I want. Thanks for reading!

  • I don;t understand what you exactly want... don't explain all the scenario, tell me just what you want. To read some input text from user input and to show it on the screen? – V. Sambor May 07 '16 at 16:23
  • Haha yeah sorry for the overexplanation. Yes, pretty much. Just trying to have the text a user enters appear in a dynamic textbox elsewhere on the screen. – freethought May 07 '16 at 21:05

1 Answers1

0

Simple enough. Just set the text value of your output to your input after the keypresses.

import flash.text.TextField;
import flash.events.KeyboardEvent;

var input:TextField = new TextField();
addChild(input);
input.type = "input";
input.text = "Type Here!";
input.addEventListener(KeyboardEvent.KEY_UP, handler);

var output:TextField = new TextField();
addChild(output);
output.text = "other text";
output.alpha = 0.5;
output.y = 25;

function handler(e:KeyboardEvent):void {
    output.text = input.text;
}
Atriace
  • 2,572
  • 1
  • 14
  • 27