отображать введенный текст в другое текстовое поле flash as3 - PullRequest
1 голос
/ 10 октября 2011

Пожалуйста, помогите мне ...

Я пытаюсь показать введенный текст в другое текстовое поле во время выполнения. Я хочу показать myOutputBox с в клипе. Код ниже:

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.text;

        createOutputBox(str);

    }



    public function createOutputBox(str:String):void

    {

        myOutputBox.background = true;

        myOutputBox.x = 200;

        addChild(myOutputBox);

        myOutputBox.text = str;

    }



}

}

1 Ответ

1 голос
/ 10 октября 2011

Немного исправил ваш код и добавил кое-что, надеюсь, это поможет вам:

  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 ="";
    }

 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...