Please help me...
I am trying to show input text to another text field on run time. I want to show the
myOutputBox
with in a movie clip. The code is below:
Actionscript 3
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.*;
import flash.events.*;
public class CaptureUserInput extends Sprite
{
private var myTextBox:TextField = new TextField();
private var myOutputBox:TextField = new TextField();
private var myText:String = "Type your text here.";
public function CaptureUserInput()
{
captureText();
}
public function captureText():void
{
myTextBox.type = TextFieldType.INPUT;
myTextBox.background = true;
addChild(myTextBox);
myTextBox.text = myText;
myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);
}
public function textInputCapture(event:TextEvent):void
{
var str:String = myTextBox.tex开发者_如何学Ct;
createOutputBox(str);
}
public function createOutputBox(str:String):void
{
myOutputBox.background = true;
myOutputBox.x = 200;
addChild(myOutputBox);
myOutputBox.text = str;
}
}
}
Fixed a little your code, and added some stuff, hope this helps you:
public class CaptureUserInput extends Sprite
{
private var initialText:String = "Type your text here.";
public var myTextBox:TextField = new TextField();
public var myOutputBox:TextField = new TextField();
public function CaptureUserInput()
{
captureText();
}
public function captureText():void
{
createInputBox();
createOutputBox();
myTextBox.text = initialText;
//reset input field so user can write
myTextBox.addEventListener(FocusEvent.FOCUS_IN, focusInputIn);
//capture text
myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);
}
//this is almost your code, refactored in a function for clarity
public function createInputBox():void
{
myTextBox.type = TextFieldType.INPUT;
myTextBox.background = true;
myTextBox.y = 100;
addChild(myTextBox);
}
//just set the text of the output to the contents of the input
public function textInputCapture(event:TextEvent):void
{
myOutputBox.text = myTextBox.text;
}
public function createOutputBox():void
{
myOutputBox.y = 200;
addChild(myOutputBox);
}
public function focusInputIn(event:Event):void
{
if(myTextBox.text == initialText)
myTextBox.text ="";
}
}
精彩评论